使用wx:key还是在setData后刷新input框.有人解答吗?
wxml文件
<!--index.wxml--> < view class = "container" > < text class = "user-motto" >{{tte}}</ text > </ view > < view wx:for = "{{objectArray}}" wx:for-item = "item" wx:key = "unique" > < view wx:if = "{{item.type==2}}" > < input class = "weui-input" wx:key = "unique" data-idx = "{{index}}" placeholder = "请输入" value = "{{item.unique}}" /> </ view > < view wx:if = "{{item.type==1}}" > < view class = "formview_right" > < picker mode = "date" wx:key = "unique" data-idx = "{{index}}" value = "{{item.val}}" bindchange = "bookPickerChange" > < view class = "weui-input" >{{item.val}}</ view > </ picker > </ view > </ view > </ view > |
js文件
Page({ data: { tte: 'Hello2 World' , objectArray: [ { val: '2017-04-10' , unique: 'unique_5' , type: 1 }, { val: '2017-04-10' , unique: 'unique_4' , type: 2 } ] }, bookPickerChange: function (e) { this .data.objectArray[e.target.dataset.idx].val = e.detail.value this .setData({ objectArray: this .data.objectArray }) } }) |
当我在input里面输入了内容, 然后点击picker修改日期, 进入bookPickerChange事件后, input里面的内容又变回默认值.
有人知道是我有地方写错了, 还是这个是一个bug呢?
2 回复
和wx:key无关,是你没有仔细看文档,this.data不能被调用/操作,修改成
Page({
data: {
tte:
'Hello2 World'
,
objectArray: this.objectArray
},
objectArray:
[
{ val:
'2017-04-10'
, unique:
'unique_5'
, type: 1 },
{ val:
'2017-04-10'
, unique:
'unique_4'
, type: 2 }
],
bookPickerChange:
function
(e) {
this.objectArray[e.target.dataset.idx].val = e.detail.value
this
.setData({
objectArray:
this.objectArray
})
}
})