Home > WeChat Applet > Mini Program Development > What should I do if the applet does not support table tags?

What should I do if the applet does not support table tags?

angryTom
Release: 2020-03-27 11:37:36
Original
5295 people have browsed it

What should I do if the applet does not support table tags?

What should I do if the mini program does not support the table tag?

The mini program does not support the table tag, but it can be implemented using the css display: table; Table style.

Recommended learning: Small program development

The specific implementation is as follows:

1. Simulate the data obtained by the dynamic background by setting the array object format in js , and then combine the contents of the array object into a group of three elements to form an array object format and then merge it into a new array object format. The reason for this is to design a row with three cells:

Page({
  data: {
    tableData: [{ //模拟动态获取到的后台数据:数组对象格式
        id: 0,
        name: 'table-th-cell'
      },
      {
        id: 1,
        name: 'table-th-cell'
      },
      {
        id: 2,
        name: 'table-th-cell'
      },
      {
        id: 3,
        name: 'table-tr-cell'
      },
      {
        id: 4,
        name: 'table-tr-cell'
      },
      {
        id: 5,
        name: 'table-tr-cell'
      },
      {
        id: 6,
        name: 'table-tr-cell'
      },
      {
        id: 7,
        name: 'table-tr-cell'
      },
      {
        id: 8,
        name: 'table-tr-cell'
      },
    ],
    threeArray: '', //模拟将后台获取到的数组对象数据按照一行3个的单元数据的格式切割成新的数组对象(简单的说:比如获取到数组是9个元素,切分成,3个元素一组的子数组)
  },
  onLoad: function() {
    let that = this;
    let threeArray = [];
    // 使用for循环将原数据切分成新的数组
    for (let i = 0, len = that.data.tableData.length; i < len; i += 3) {
      threeArray.push(that.data.tableData.slice(i, i + 3));
    }
    console.log(threeArray);
    that.setData({
      threeArray: threeArray
    })
  },
})
Copy after login

2 , set wxml:

<view class="table">
  <block wx:for=&#39;{{threeArray}}&#39; wx:key=&#39;*this&#39; wx:for-item=&#39;oneArray&#39;>
<!-- 注意嵌套的数组对象 -->
    <view class="table-tr" wx:if=&#39;{{index<1}}&#39;>
      <block wx:for=&#39;{{oneArray}}&#39; wx:key=&#39;id&#39;>
        <view class="table-th">{{item.name}}</view>
      </block>
    </view>
    <view class="table-tr" wx:else>
      <block wx:for=&#39;{{oneArray}}&#39; wx:key=&#39;id&#39;>
        <view class="table-td">{{item.name}}</view>
      </block>
    </view>
  </block>
</view>
Copy after login

3, set wxss:

.table {
  display: table;
  width: 100%;
  /* border-collapse 属性设置表格的边框是否被合并为一个单一的边框,解决相邻单元格边框未合并导致有些边框变粗的视觉效果 */
  border-collapse: collapse;
  overflow-x: hidden;
}
.table-tr {
  display: table-row;
  width: 100%;
  height: 200rpx;
}
.table-th {
  display: table-cell;
  font-weight: bold;
  border: 1px solid black;
  text-align: center;
  vertical-align: middle;
  background-color: #ccc;
}
.table-td {
  display: table-cell;
  border: 1px solid black;
  text-align: center;
  vertical-align: middle;
}
Copy after login

The effect is as follows:

What should I do if the applet does not support table tags?

The above is the detailed content of What should I do if the applet does not support table tags?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template