WXML:
<block wx:for="{{cateItems[curIndex].children}}" wx:key="{{index}}">
<view style="position:relative">
<view class="nav_right_items">
<text>{{item.name}}</text>
<text style="color:red">¥{{item.price}}/斤</text>
</view>
<view class="counts">
<text class="reduce {{status}}" bindtap="reduce" data-index="{{index}}">-</text>
<input class="number" value="{{item.num}}" data-index="{{index}}" bindinput="bindValue"></input>
<text class="add" bindtap="add" data-index="{{index}}">+</text>
</view>
</view>
</block>
JS:
data: {
arr: ["蔬菜","调味品","米类","面类","油类","干果类","水产类","肉类","杂粮类","冻货类","酒水类","芽菜类","烫菜类"],
index: 1,
currentTab: 0,
cateItems:[
{
cate_id:1,
cate_name:'根茎类',
children: [
{
child_id: 1,
name: '(皱皮)辣椒',
price: 6,
num:0
},
{
child_id: 2,
name: '黄皮洋葱',
price: 1.5,
num:0
},
{
child_id: 3,
name: '苦菊',
price: 3.5,
num:0
},
{
child_id: 4,
name: '蛋皮',
price: 6,
num:0
}
]
},
curNav:1,
curIndex:0,
stasus:"disabled"
},
add:function(e){
let index = e.currentTarget.dataset.index;
var curIndex = this.data.curIndex;
var children = this.data.cateItems[curIndex].children[index];
console.log(children)
var num = children.num;
var status = num<1?"disabled":"normal";
num = num + 1;
console.log(num)
children.num = num;
this.setData({
num:num,
status:status
})
console.log(children)
console.log(num)
},
我this.setData里面写的不对吗