@小程序picker组件下拉显示[object object],而前台能够显示出来
1.1前端错误展示
1.2 错误代码
<picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}" >
<view class="picker">
自提点选择:{{array[index].shop_address}}
</view>
</picker>
data: {
array: [],
index: 0
},
onLoad: function (options) {
let that = this
db.collection('zitidian').get({
success: function (res) {
console.log('获取自提点成功', res)
that.setData({
array: res.data,
})
},
fail: function (res) {
console.log('获取自提点失败', res)
}
})
},
bindPickerChange: function (e) {
console.log('显示数据成功', e)
this.setData({
index: e.detail.value
})
},
1.3如何改正
在中加入range-key=“shop_address”,就可以正常显示
range就是数组名,value是元素自带的下标,range-key是在二维数组中具体某列的某个值
<picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}" range-key="shop_address">
<view class="picker">
自提点选择:{{array[index].shop_address}}
</view>
</picker>