小程序多属性选择

在这里插入图片描述
效果图

wxml代码

<view class='wraps'>

  <view class='wrap' wx:for="{{options}}" wx:for-index="indexs" wx:for-item="oname">
    <view class='name'>{{oname.name}}</view>
    <view class='des'>
    
      <view class="{{item.checked?'active':'desitem'}}" wx:for="{{oname.items}}" catchtap="stoggle" data-parentindex="{{indexs}}" data-currentindex="{{index}}">
      
        {{item.msg}}
      
      </view>
      
      
    </view>
  </view>
  

</view>

wxss代码

.wraps{
  /* width: 100%; */
  padding: 20rpx;
}


.name{
 
  line-height: 100rpx;
}
.des{
  width: 100%;
  
  border: 1px solid #ccc;
  display: flex;
  /* flex-direction: row; */
  /* flex-wrap: wrap; */
}
.desitem{
  display: inline-block;
  background: #ccc;
  padding: 10rpx 20rpx;
  margin-right: 20rpx;
  border-radius: 10rpx;
  
 }
.active{
   background: #f00;
   color: #fff;
 }

JS代码

// pages/text4/text4.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

    options: [{
      items: [{
        'msg': '绿色',
        "id": "11",
        "chekced": true
      }, {
        'msg': "红色",
        "id": "12"
      }],
      name: "颜色"
    }, {
      items: [{
        'msg': "XXX",
        "id": "13"
      }, {
        'msg': "L",
        "id": "14"
      }, {
        'msg': "XXL",
        "id": "15"
      }],
      name: "型号"
    }, {
      items: [{
        'msg': "32G",
        "id": "16"
      }, {
        'msg': "8G",
        "id": "17"
      }, {
        'msg': "4G",
        "id": "18"
      }],
      name: "版本"
    }]
  },

  stoggle: function (e) {
    console.log(e);
    var parentIndex = e.currentTarget.dataset.parentindex;
    var currentIndex = e.currentTarget.dataset.currentindex;


    var options = this.data.options;



    for (var i = 0; i < options.length; i++) {

      if (i == parentIndex) {

        console.log(parentIndex);
        for (var j = 0; j < options[i].items.length; j++) {

          options[i].items[j].checked = false;
        }

        options[i].items[currentIndex].checked = true;
      }
    }

    console.log(options);
    this.setData({
      options: options
    })



  }


})

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值