picker多级选择器的使用————小程序

picker多级选择器的使用————小程序

picker是选择器来着,既然选择了,就希望可以获取选择的数据。

index.html

<view>picker获取数据</view>
<view class="cu-form-group margin-top">
  <picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}">//改变bindchange后,执行bindPickerChange。
    <view class="picker">当前选择:{{array[index]}}</view>
  </picker>
</view>
<view class="picker">当前选择:{{array[index]}}</view>//任何数据能读出来的才叫好数据。
<view class="picker">当前选择:{{userChange}}</view>

index.js

  bindPickerChange: function (e) {
    console.log('picker发送选择改变,携带下标为', e.detail.value)//获取选择的值的下标value
    console.log('picker发送选择改变,携带值为', this.data.array[e.detail.value])//获取选择的值
    this.setData({
      index: e.detail.value,//值要定义过才能用
      userChange:this.data.array[e.detail.value]//值要定义过才能用
    })
  },

猜你喜欢

转载自www.cnblogs.com/cth0/p/11568725.html
今日推荐