我有这个一个界面 实现
dataArray:[{id:'1',name:'一斤',items:[{id:'2',name:'大',price:0,stock:0},{id:'3',name:'中',price:0,stock:0}] },{...}]
现在有个问题 我输入几次之后 会把之前的内容覆盖
比如 :输入第一行(价格+库存) 1 2
输入 第三行(价格+库存) 4 5
后面打印输出 一三行的结果值都是 4 5 值被覆盖了 我不知道是真么原因
<view class="content-item-head">
<view class="head-item"></view>
<view class="head-item">规格</view>
<view class="head-item">价格(元)</view>
<view class="head-item">库存(件)</view>
</view>
<view class="content-item-row {{ idx%2==0?'itemBackground':'' }}" wx:key="index" wx:for="{{item.items}}" wx:for-item="obj" wx:for-index="idx">
<view class="head-item ">{{idx==filters.toFix(item.items.length/3) ? item.name :''}}</view>
<view class="head-item"> {{obj.name}} </view>
<view class="head-item">
<input class="item-input" bindblur="onInput" data-type='price' data-pindex="{{index}}" data-index="{{idx}}" maxlength="6" placeholder="¥输入金额" type="digit" value="{{ obj.price }}" ></input>
</view>
<view class="head-item">
<input class="item-input" bindblur="onInput" data-type='stock' data-pindex="{{index}}" data-index="{{idx}}" maxlength="5" placeholder="输入库存" type="number" value="{{ obj.stock}}"></input>
</view>
</view>
</view>
onInput(e) {
var value = e.detail.value
let index = e.currentTarget.dataset.index //子容器的index
let pindex = e.currentTarget.dataset.pindex //父容器的index
let type = e.currentTarget.dataset.type //父容器的index
if (type == 'price') {
value = this.money(value)//处理金额价格
}
let key = 'dataArray[' + pindex + '].items[' + index + '].' + type
this.setData({
[key]: value
})
},
你好,请提供能复现问题的简单代码片段
https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
请学会如何「提问」(👈戳我)