微信小程序 picker 组件,当 range 为 Object Array 类型时
wxml:
<picker bindchange="bindPickerChange" value="{{index}}" range-key="name" range="{{objectArray}}"> <view class="picker"> 当前选择:{{objectArray[index].name}} </view> </picker>
js:
Page({ data: { objectArray: [ { id: 0, name: '美国' }, { id: 1, name: '中国' }, { id: 2, name: '巴西' }, { id: 3, name: '日本' } ] }, bindPickerChange: function(e) { console.log('picker发送选择改变,携带值为', e.detail.value) var index = e.detail.value; var currentId = this.data.objectArray[index].id; this.setData({ index: e.detail.value }) } })