多个picker 会出现页面联动 index错乱
解决方法1:
1、通过记录当前点击的对象在数组里的下标index
2、再赋值给当前下标为index的对象
<repeat for="{{selectedlist}}" key="templateList" index="index" item="template">
<view wx:if="{{template.fieldname === '日期'}}">
<view class="user-name ub ub-ac item">
<view class="mark">
<text class="asterisk">*</text>日期
</view>
<view class="ub-f1 ub ub-ac" @tap="recordIndex({{index}})">
<picker mode="date" name="birthday" value="{{template.value}}" bindchange="bindDateChange">
<view class="picker">
{{template.value}}
</view>
</picker>
</view>
<view class="icon iconfont icon-more select-item"></view>
</view>
</view>
</repeat>
data = {
selectedlist:[], //
operaIndex: 0 //记录所点击的index
}
methods:{
recordIndex(index){
this.operaIndex = index;
this.$apply()
},
bindDateChange: function(e) {
console.log('picker发送选择改变,携带值为', e.detail.value)
this.selectedlist[this.operaIndex].value = e.detail.value
this.$apply()
},
}