Practical examples of using wx:for and wx:for-item
<span style="font-family:Microsoft Yahei, Hiragino Sans GB, Helvetica, Helvetica Neue, 微软雅黑, Tahoma, Arial, sans-serif">This time I will bring you a practical case of using wx:for and wx:for-item. What are the <a href="http://www.php.cn/code/10182.html" target="_blank"> precautions</a> for using wx:for and wx:for-item? The following is a practical case, let’s take a look. </span>
<span style="font-family:Microsoft Yahei, Hiragino Sans GB, Helvetica, Helvetica Neue, 微软雅黑, Tahoma, Arial, sans-serif">z</span>wx:for="{{list}}"
is used to loop the array, and list is For the array name wx:for-item="items"
is used to define the variable of each element during a loop. If it is
is looped out as follows: <view wx:for="{{list}}">
{{index}} {{item.name}}
</view>
If it is a two-dimensional or even
multi-dimensional array, loop as follows: <view wx:for="{{parentList}}">
{{item.id}}
<view wx:for="{{item.childList}}" wx:for-item="items">
{{items.name}}{{item.account}}
</view>
</view>
for (var i = 0 ; i < list.length; i++) {
var xxx = list[i];
}
<view wx:for="{{list}}" wx:for-item="xxx"></view>
Remember: wx:for is a loop array , wx:for-item is to assign an alias to the list
The following are several incorrect uses, please use them with caution:
1. Use wx:for-item directly, so the loop will not come out List
<view wx:for-item="{{list}}"> {{index}} {{item.name}} </view>
2. Use wx:for-item with caution in sub-loops
<view wx:for="{{parentList}}"> {{item.id}} <view wx:for-item="{{item.childList}}" wx:for-item="items"> {{items.name}}{{items.account}} </view>
Correct usage of wx:for and wx:for-item in WeChat applet
wx :for="{{list}}" is used to loop the array, and list is the array name wx:for-item="items" is used to define the variables of each element during the loop
If it is a one-dimensional array, it is looped out as follows:
<view wx:for="{{list}}"> {{index}} {{item.name}} </view>
In the above code, item is the alias of list.
If it is a two-dimensional or even multi-dimensional array, loop as follows:
<view wx:for="{{parentList}}"> {{item.id}} <view wx:for="{{item.childList}}" wx:for-item="items"> {{items.name}}{{item.account}} </view> </view> for (var i = 0 ; i < list.length; i++) { var xxx = list[i]; }
is equivalent to
<view wx:for="{{list}}" wx:for-item="xxx"></view>
Remember: wx:for is a loop array, wx:for-item That is to assign an alias to the list
The following are several incorrect uses, please use them with caution:
1. Use wx:for-item directly, so that the list cannot be looped
<view wx:for-item="{{list}}"> {{index}} {{item.name}} </view>
2. Use wx:for-item with caution in sub-loops
<view wx:for="{{parentList}}"> {{item.id}} <view wx:for-item="{{item.childList}}" wx:for-item="items"> {{items.name}}{{items.account}} </view>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
How FileReader implements a file readerDetailed explanation of the use of slot sockets in vue componentsThe above is the detailed content of Practical examples of using wx:for and wx:for-item. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP Practice: Code Example to Quickly Implement the Fibonacci Sequence The Fibonacci Sequence is a very interesting and common sequence in mathematics. It is defined as follows: the first and second numbers are 0 and 1, and from the third Starting with numbers, each number is the sum of the previous two numbers. The first few numbers in the Fibonacci sequence are 0,1,1.2,3,5,8,13,21,...and so on. In PHP, we can generate the Fibonacci sequence through recursion and iteration. Below we will show these two

This article brings you relevant knowledge about uniapp cross-domain, and introduces issues related to subcontracting of uniapp and mini programs. Each mini program that uses subcontracting must contain a main package. The so-called main package is where the default startup page/TabBar page is placed, and some public resources/JS scripts are required for all sub-packages; while sub-packages are divided according to the developer's configuration. I hope it will be helpful to everyone.

The data export function is a very common requirement in actual development, especially in scenarios such as back-end management systems or data report export. This article will take the Golang language as an example to share the implementation skills of the data export function and give specific code examples. 1. Environment preparation Before starting, make sure you have installed the Golang environment and are familiar with the basic syntax and operations of Golang. In addition, in order to implement the data export function, you may need to use a third-party library, such as github.com/360EntSec

MySQL table design practice: Create an e-commerce order table and product review table. In the database of the e-commerce platform, the order table and product review table are two very important tables. This article will introduce how to use MySQL to design and create these two tables, and give code examples. 1. Design and creation of order table The order table is used to store the user's purchase information, including order number, user ID, product ID, purchase quantity, order status and other fields. First, we need to create a table named "order" using CREATET

Java Development Practice: Integrating Qiniu Cloud Storage Service to Implement File Upload Introduction With the development of cloud computing and cloud storage, more and more applications need to upload files to the cloud for storage and management. The advantages of cloud storage services are high reliability, scalability and flexibility. This article will introduce how to use Java language development, integrate Qiniu cloud storage service, and implement file upload function. About Qiniu Cloud Qiniu Cloud is a leading cloud storage service provider in China, providing comprehensive cloud storage and content distribution services. Users can use Qiniu Yunti

In-depth study of Elasticsearch query syntax and practical introduction: Elasticsearch is an open source search engine based on Lucene. It is mainly used for distributed search and analysis. It is widely used in full-text search of large-scale data, log analysis, recommendation systems and other scenarios. When using Elasticsearch for data query, flexible use of query syntax is the key to improving query efficiency. This article will delve into the Elasticsearch query syntax and give it based on actual cases.

Become a Go language master: Sharing learning paths and practical experience Go language has been favored by developers since its birth. Its simplicity, efficiency, and outstanding concurrency performance have attracted more and more developers to join the learning and application of Go language. ranks. This article will share a learning path to become a master of the Go language. At the same time, combined with practical experience, we will provide some code examples for your reference. Learning path 1. Learn basic knowledge. No matter when learning any language, the first thing to master is the basic knowledge. The basic knowledge of Go language mainly includes data types,

Vue Practical Combat: Date Picker Component Development Introduction: The date picker is a component often used in daily development. It can easily select dates and provides various configuration options. This article will introduce how to use the Vue framework to develop a simple date picker component and provide specific code examples. 1. Requirements analysis Before starting development, we need to conduct a requirements analysis to clarify the functions and characteristics of the components. According to the common date picker component functions, we need to implement the following function points: Basic functions: able to select dates, and
