循环列表点击单选框,以及反选功能

在小程序的循环列表中,点击某条目,该条目下面的单选框被选中,以及高亮,再点击或者点击其他条目,单选框取消选中。

 

xml代码


<view class="titWrapper">

</view>
<block>
  <view  wx:for="{{listData}}" class="item_wrapper class='{{idx == currentidx&& choose==true ? 'item_cur':''}}'"  wx:for-index="idx" wx:for-item="{{item}}" wx:key="key" bindtap="clickItem" data-index="{{idx}}">
    <view class="left_con" >
      <view class="left_tp">
        <text class="type cur1">类别</text>
        <text class="card">8933 **** 5838 </text>
      </view>
      <view class="left_bt">
      <text>姓名:</text><text>xxxxx7</text>
      </view>
    </view>
    <view class="right_con">
    <radio checked='{{idx == currentidx&& choose==true? true : false}}' value="1" class="radio"></radio>
    </view>
  </view>
</block>

js代码

 data: {
    listData: [1, 2, 3],
    choose: false,
    currentidx: 0,
    selectIdx2: 0,
  },

clickItem: function(e) {
    console.log(e);
    //记录上次点击的对象的index
    var oldidx = this.data.currentidx;
    //记录当前点击的对象的index
    var currentidx = e.currentTarget.dataset.index;
    if (oldidx == currentidx) {
      var choose = this.data.choose;
      this.setData({
        currentidx: currentidx,
        choose: !choose
      })
    } else {
      this.setData({
        currentidx: currentidx,
        choose: true
      });
    }
    console.log(oldidx + "---------" + this.data.currentidx);


  },

参考大神链接:https://blog.csdn.net/anLazyAnt/article/details/72471180?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值