Mini Programs enable product attribute selection or specification selection

Mini Programs enable product attribute selection or specification selection

This article shares the specific code for implementing product attribute selection or specification selection in a mini program for your reference. The specific content is as follows

Achieve results

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: {
 //Data list: [
   {
    "goods_option_id": 1737,
    "option_id": 1737,
    "name": "Ice Degree",
    "option_value": [
     {
      "goods_option_value_id": 3606,
      "option_value_id": 3606,
      "name": "Normal Ice",
      "image": "xxxxxx.png"
     },
     {
      "goods_option_value_id": 3605,
      "option_value_id": 3605,
      "name": "Shao Bing",
      "image": "xxxxxx.png"
     },
     {
      "goods_option_value_id": 3604,
      "option_value_id": 3604,
      "name": "Hot Drinks",
      "image": "xxxxxx.png"
     }
    ]
   },
   {
    "goods_option_id": 1738,
    "option_id": 1738,
    "name": "Sugar Content",
    "option_value": [
     {
      "goods_option_value_id": 3608,
      "option_value_id": 3608,
      "name": "Normal Sugar",
      "image": "xxxxxx.png"
     },
     {
      "goods_option_value_id": 3607,
      "option_value_id": 3607,
      "name": "Less Sugar",
      "image": "xxxxxx.png"
     }
    ]
   },
   {
    "goods_option_id": 1737,
    "option_id": 1737,
    "name": "Ice Degree",
    "option_value": [
     {
      "goods_option_value_id": 3606,
      "option_value_id": 3606,
      "name": "Normal Ice",
      "image": "xxxxxx.png"
     },
     {
      "goods_option_value_id": 3605,
      "option_value_id": 3605,
      "name": "Shao Bing",
      "image": "xxxxxx.png"
     },
     {
      "goods_option_value_id": 3604,
      "option_value_id": 3604,
      "name": "Hot Drinks",
      "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
   })
  });
 }

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • WeChat applet realizes linkage selection of product attributes
  • WeChat Mini Program Product Details Page Specification Attribute Selection Sample Code

<<:  How to modify iTunes backup path under Windows

>>:  Example of how to generate random numbers and concatenate strings in MySQL

Recommend

Native JS to achieve cool paging effect

This article uses an example to share with you a ...

VSCode+CMake+Clang+GCC environment construction tutorial under win10

I plan to use C/C++ to implement basic data struc...

MySQL 8.0.2 offline installation and configuration method graphic tutorial

The offline installation method of MySQL_8.0.2 is...

Writing daily automatic backup of MySQL database using mysqldump in Centos7

1. Requirements: Database backup is particularly ...

Examples of using MySQL covering indexes

What is a covering index? Creating an index that ...

Detailed explanation of Linux rpm and yum commands and usage

RPM package management A packaging and installati...

What knowledge systems do web designers need?

Product designers face complex and large manufactu...

A brief discussion of the interesting box model of CSS3 box-sizing property

Everyone must know the composition of the box mod...

How to update Ubuntu 20.04 LTS on Windows 10

April 23, 2020, Today, Ubuntu 20.04 on Windows al...

Implementation steps for enabling docker remote service link on cloud centos

Here we introduce the centos server with docker i...

mysql5.7.21 utf8 encoding problem and solution in Mac environment

1. Goal: Change the value of character_set_server...

MySQL database table partitioning considerations [recommended]

Table partitioning is different from database par...

MySQL performance optimization tips

MySQL Performance Optimization MySQL is widely us...