微信小程序遍历循环中点击添加样式

来源:互联网 发布:java动态bean 编辑:程序博客网 时间:2024/06/07 04:44

.wxml中:

<viewclass='section'>

<scroll-view id='sv' scroll-y style="width:150rpx;height:{{hei}}px;">
<block wx:for="{{leftMenu}}"wx:key='this'>
<block wx:if="{{index == clickId}}">
<view bindtap='changeWhite' class='fff' id='{{index}}'>
{{item}}
</view>
</block>
<blockwx:else>
<view bindtap='changeWhite' class='eee' id='{{index}}'>
{{item}}
</view>
</block>
</block>
</scroll-view>
</view>
.js中
data: {
clickId:0,
},
changeWhite:function(res){
var cla = res.currentTarget.id;
console.log(res.currentTarget.id);
this.setData({
clickId:cla
})
},
阅读全文
0 0
原创粉丝点击