三元运算无法执行,?

小程序 文章 2021-04-08 16:42 373 0 全屏看文

AI助手支持GPT4.0

三元运算无法执行,?The ternary operation cannot be executed,

三元运算无法执行,?

小弟想做个样式更改的,但不知为啥三元运算没结果出来 求大佬指导

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    })  }

小弟想做个样式更改的,但不知为啥三元运算没结果出来 求大佬指导 hxml      {{cata_item.cat_name}}   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    })  }

回答:

null:
{{index==cur_num?'active':''}}
ᝰꫛꫀꪝ .:

<view wx:for="{{navList}}" wx:key="item" data-id="{{item.id}}" data-current="{{index}}" bindtap="swichNav" class="{{index == currentTab ? 'active' : ''}}">{{item.name}}</view>

wx:for放在前面 class在后面,可查看以上代码

brave:
{{num==cur_num? 'active' : ' '}}" 改成 {{index==cur_num? 'active' : ' '}}
AnDrew:

if 和 for 不要在同一个标签使用

-EOF-

AI助手支持GPT4.0