微信小程序picker组件使用示例

示例:

wxml页面:

 <picker name="picker_machine11" class="cybm_pic_1" range="{{categoryList}}" value="{{'categoryid'}}" range-key='name' bindchange="bindChangeCate">
        <span class="picker">
          <view class='flex-item'>{{showCategory}}</view>
        </span>
      </picker>

其中,range是数组类型:[{id:'',name:''}],value为选中后的值,range-key为显示字段,bindchange为绑定事件,绑定事件写法如下:

bindChangeCate: function (e) {
    let index = e.detail.value;
    let text = this.data.categoryList[index].name;
    if (text == '全部') {
      text = '职位类型'
    }
    this.setData({
      cate_index: e.detail.value,
      showCategory: text + '',
      categoryid: this.data.categoryList[index].id
    });
    //查询事件写在此处
  },

 

posted @ 2022-09-20 09:43  Shapley  阅读(220)  评论(0编辑  收藏  举报