微信小程序循环列表点击当前添加class类名

<view class="menber_bd {{ index === currentid ? 'on' : '' }}" bindtap="xuanze" data-index="{{index}}" wx:for="{{list}}" wx:key="index">
	<view class="menber_li">{{item.name}}</view>
</view>

data: {

    list:[

      { id: 1, name: ‘选项1’ },

      { id: 2, name: ‘选项2’ },

      { id: 3, name: ‘选项3’ },

      { id: 4, name: ‘选项4’ },

      { id: 5, name: ‘选项5’ },

      { id: 6, name: ‘选项6’ },

    ],

  },

xuanze:function(e){
    this.setData({
      currentid:e.currentTarget.dataset.index
    })
  },

发表评论