search
HomeWeChat AppletMini Program DevelopmentUsage of wx:for and wx:for-item in WeChat mini program

This article mainly introduces the correct usage of WeChat applet wx:for and wx:for-item. wx:for is a loop array, and wx:for-item is to assign an alias to the list. The article lists a few for you. Wrong usage, let’s learn together

wx:for="{{list}}" is used to loop the array, and list is the array namewx:for-item= "items" is used to define the variables of each element during a loop.

If it is a one-dimensional array, loop it 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 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 will not appear in the loop

<view wx:for-item="{{list}}">
{{index}} {{item.name}}
</view>

2. Use wx:for- with caution in sub-loops item

<view wx:for="{{parentList}}">
 {{item.id}}
 <view wx:for-item="{{item.childList}}" wx:for-item="items">
 {{items.name}}{{items.account}}
 </view>

The correct usage of WeChat applet wx:for and wx:for-item

wx:for="{{list} }" is used to loop the array, and list is the array name wx:for-item="items" which is used to define the variable of each element during the loop

If it is a one-dimensional array, follow the following The method is looped out:

<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 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 will not appear in the loop

<view wx:for-item="{{list}}">
{{index}} {{item.name}}
</view>

2. Use wx:for- with caution in sub-loops item

<view wx:for="{{parentList}}">
 {{item.id}}
 <view wx:for-item="{{item.childList}}" wx:for-item="items">
 {{items.name}}{{items.account}}
 </view>

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to obtain AppID when developing WeChat mini program

How to use WeChat mini program to upload pictures

The above is the detailed content of Usage of wx:for and wx:for-item in WeChat mini program. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.