小弟想做个样式更改的,但不知为啥三元运算没结果出来 求大佬指导
hxml
<scroll-view class="left_content" scroll-y>
<view class="cata_name {{num==cur_num? 'active' : ' '}}" wx:for="{{catagory_left_list}}" wx:for-item="cata_item" wx:key="cata" data-num="{{index}}" bindtap="changePage">{{cata_item.cat_name}}</view>
</scroll-view>
js
data: {
catagory_left_list:[],
catagory_right_list:[],
cur_num:0
}
changePage:function(e){
console.log(e)
let index = e.currentTarget.dataset.num;
this.setData({
cur_num:index,
catagory_right_list:this.catas[e.currentTarget.dataset.num].children
})
}
{{index==cur_num?'active':''}}
<scroll-view class="left_content">
<view class="cata_name {{index==cur_num? 'active' : ' '}}"
wx:for="{{catagory_left_list}}" wx:key="index"
data-index="{{index}}"bindtap="changePage"> {{item.cat_name}}
</view>
</scroll-view>
changePage:function(e){
console.log(e)
let index = e.currentTarget.dataset.index;
this.setData({
cur_num:index,
})
}
{{num==cur_num? 'active' : ' '}}" 改成 {{index==cur_num? 'active' : ' '}}
if 和 for 不要在同一个标签使用