微信小程序商品规格布局+样式+嵌套循环

只有红框框里的样式噢,请看下图→

功能:布局样式+循环点击变色+嵌套

在这里插入图片描述

WXML:

<!-- 商品规格 -->
<view class="selectsize_content">
  <block wx:for="{{properties}}" wx:key="item" wx:for-index="id">
    <view class="content_title">{{item.name}}</view>
    <view class='content_list'>
      <block wx:for="{{item.childsCurGoods}}" wx:key="items">
        <text class="{{ item.isSelect?'active':''}}" data-select-index=" {{id}}" data-attr-index="{{index}}" data-propertyId="{{item.propertyid}}:{{item.id}}" 
        data-content="{{properties}}" bindtap='clickMenu'>{{item.name}}</text>
      </block>
    </view>
  </block>
</view>

JS:

  // 商品规格
  clickMenu: function (event) {
    let that = this
    // console.log(event)
    let selectIndex = event.currentTarget.dataset.selectIndex;
    let attrIndex = event.currentTarget.dataset.attrIndex;
    let content = event.currentTarget.dataset.content
    var count = content[selectIndex].childsCurGoods.length;
    for (var i = 0; i < count; i++) {
      content[selectIndex].childsCurGoods[i].isSelect = false
    }
    content[selectIndex].childsCurGoods[attrIndex].isSelect = true;
    // 必须重新渲染数据-------------为了添加isSelect属性
    that.setData({
      properties: content
    })
  }

WXSS:

.selectsize_content{
  width:100%;
  height:450rpx;
  border-bottom:2rpx solid lightgray;
}

.content_title{
    line-height:100rpx;
    margin-left:20rpx;
}

.content_list{
  line-height:100rpx;
  margin-left:20rpx;
}

.content_list text{
  padding:20rpx;
  border:2rpx solid lightgray;
  margin-right:20rpx;
}

// 商品属性选中后切换样式
.active{
  border-color:red;
  color:red;
}

注:复制粘贴即可使用 (∩_∩)!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值