Home > Web Front-end > JS Tutorial > body text

Practical examples of using wx:for and wx:for-item

php中世界最好的语言
Release: 2018-05-02 14:51:09
Original
1572 people have browsed it

<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

one The dimensional array

is looped out as follows:

In the above code, item is the alias of list.

If it is a two-dimensional or even

multi-dimensional array

, loop as follows:

is equivalent to

<view wx:for="{{list}}" wx:for-item="xxx"></view>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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];
}
Copy after login
Copy after login

is equivalent to

<view wx:for="{{list}}" wx:for-item="xxx"></view>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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 reader


Detailed explanation of the use of slot sockets in vue components

The 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!