小程序中使用表格功能

小程序中使用表格

效果展示:
在这里插入图片描述
1、wxml代码

<view class="table">
        <view class="tr bg-w">
          <view class="th">Name</view>
          <view class="th">UT Target</view>
          <view class="th ">WTD</view>
          <view class="th ">MTD</view>
        </view>
        <block wx:for="{{listData}}" wx:key="index">
          <view class="tr {{index%2 === 0?'':'bg-g'}}">
            <view class="td">{{item.code}}</view>
            <view class="td">{{item.text}}</view>
            <view class="td">{{item.type}}</view>
            <view class="td">{{item.text}}</view>
            
          </view>
        </block>
      </view>

2、wxss代码

.table {
  margin: 11rpx 14rpx 0 14rpx;
 }
 .tr {
  display: flex;
  width: 100%;
  justify-content: center;
  height: 72rpx;
  align-items: center;
  font-size: 22rpx;
  color: #666666;
 }
 .td {
  width:40%;
  justify-content: center;
  text-align: center;
  align-items: center;
  color: #666666;
 }
 .bg-g{
  background: #F6F7F9;
 }
 .th {
  width: 40%;
  justify-content: center;
  background: #E9E9E9;
  color: #333333;
  display: flex;
  height: 72rpx;
  align-items: center;
  font-size: 22rpx;
 }

3、js代码

 listData: [{
        "code": "01",
        "text": "text1",
        "type": "type1",
        "YTD": "0.34"
      },
      {
        "code": "02",
        "text": "text2",
        "type": "type2",
        "YTD": "0.78"
      },
      {
        "code": "03",
        "text": "text3",
        "type": "type3",
        "YTD": "0.80"
      },
      {
        "code": "04",
        "text": "text4",
        "type": "type4",
        "YTD": "0.90"
      },
      {
        "code": "05",
        "text": "text5",
        "type": "type5",
        "YTD": "0.78"
      }
    ],
  • 8
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
小程序实现表格下拉框筛选功能,可以分为以下步骤: 1. 在wxml文件使用picker组件实现下拉框,例如: ``` <view class="picker"> <picker mode="selector" range="{{selector}}" bindchange="bindPickerChange"> <view class="picker-text">{{selector[selectorIndex]}}</view> </picker> </view> ``` 其,selector是下拉框的选项列表,selectorIndex是当前选的选项的索引值,bindPickerChange是下拉框选项变化时的回调函数。 2. 在js文件,初始化selector、selectorIndex等数据,例如: ``` data: { selector: ['全部', '选项1', '选项2', '选项3'], selectorIndex: 0 }, ``` 3. 在bindPickerChange回调函数,根据选项的索引值,筛选出符合条件的数据,并更新data的tableData,例如: ``` bindPickerChange: function(e) { this.setData({ selectorIndex: e.detail.value }) var selectedValue = this.data.selector[e.detail.value]; if (selectedValue == '全部') { this.setData({ tableData: this.data.originalTableData }) } else { var filteredData = this.data.originalTableData.filter(function(item) { return item.option == selectedValue; }) this.setData({ tableData: filteredData }) } }, ``` 其,originalTableData是原始的表格数据,tableData是筛选后的数据,根据选项的值,使用filter方法过滤出符合条件的数据。最后更新tableData即可。 4. 在onLoad生命周期函数,初始化originalTableData和tableData数据,例如: ``` onLoad: function(options) { // 初始化表格数据 var tableData = [ {name: '张三', option: '选项1'}, {name: '李四', option: '选项2'}, {name: '王五', option: '选项1'}, {name: '赵六', option: '选项3'} ]; this.setData({ originalTableData: tableData, tableData: tableData }) }, ``` 这样,就可以实现小程序表格下拉框筛选功能了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值