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]//值要定義過才能用
})
},