亲宝软件园·资讯

展开

小程序商品选择 小程序实现商品属性选择或规格选择

纸上画佳人 人气:0
想了解小程序实现商品属性选择或规格选择的相关内容吗,纸上画佳人在本文为您仔细讲解小程序商品选择的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:小程序商品属性选择,小程序商品规格选择,小程序商品选择,下面大家一起来学习吧。

实现效果

1.wxml

<view wx:for="{{list}}" wx:key="index" wx:key="index" wx:for-index="childIndex" style="margin: 40px 0">
  <view>{{item.name}}</view>
 
 
  <view class="s" wx:for="{{item.option_value}}" wx:key="index" >
   <text class="{{indexArr[childIndex] == index ? 'active':''}}" bindtap="choice" data-fid="{{childIndex}}" data-id="{{index}}">
    {{item.name}}
   </text>
  </view>
</view>

2.js

data: {
 //数据
  list: [
   {
    "goods_option_id": 1737,
    "option_id": 1737,
    "name": "冰度",
    "option_value": [
     {
      "goods_option_value_id": 3606,
      "option_value_id": 3606,
      "name": "正常冰",
      "image": "xxxxxx.png"
     },
     {
      "goods_option_value_id": 3605,
      "option_value_id": 3605,
      "name": "少冰",
      "image": "xxxxxx.png"
     },
     {
      "goods_option_value_id": 3604,
      "option_value_id": 3604,
      "name": "热饮",
      "image": "xxxxxx.png"
     }
    ]
   },
   {
    "goods_option_id": 1738,
    "option_id": 1738,
    "name": "糖度",
    "option_value": [
     {
      "goods_option_value_id": 3608,
      "option_value_id": 3608,
      "name": "正常糖",
      "image": "xxxxxx.png"
     },
     {
      "goods_option_value_id": 3607,
      "option_value_id": 3607,
      "name": "少糖",
      "image": "xxxxxx.png"
     }
    ]
   },
   {
    "goods_option_id": 1737,
    "option_id": 1737,
    "name": "冰度",
    "option_value": [
     {
      "goods_option_value_id": 3606,
      "option_value_id": 3606,
      "name": "正常冰",
      "image": "xxxxxx.png"
     },
     {
      "goods_option_value_id": 3605,
      "option_value_id": 3605,
      "name": "少冰",
      "image": "xxxxxx.png"
     },
     {
      "goods_option_value_id": 3604,
      "option_value_id": 3604,
      "name": "热饮",
      "image": "xxxxxx.png"
     }
    ]
   }
  ],
  arr: [],
  indexArr: []
 },

choice(e) {
  const fid = e.currentTarget.dataset.fid;
   const id = e.currentTarget.dataset.id;
  const arr = this.data.arr,
     arr2 = this.data.indexArr;
    
   arr[fid] = this.data.list[fid].option_value[id].name;
  arr2[fid] = id;

  this.setData({
   arr: arr,
   indexArr: arr2
  })
 },
 
 onLoad: function (options) {
  const res = this.data.indexArr;
  this.data.list.forEach((e,i) => {
   res[i] = 0;
   this.setData({
    indexArr: res
   })
  });
 }

加载全部内容

相关教程
猜你喜欢
用户评论