wx:for and wx:for-item small program development

php中世界最好的语言
Release: 2018-06-12 10:12:56
Original
2063 people have browsed it

This time I will bring you some precautions when developing wx:for and wx:for-item small programs. The following is a practical case. Let’s take a look.

wx:for="{{list}}"is used to loop through the array, and list is the array namewx:for-item="items"That is

used to define the variables of each element in a loop process. If it is a one-dimensional array, it is looped out as follows:

 {{index}} {{item.name}} 
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:

 {{item.id}}  {{items.name}}{{item.account}}   for (var i = 0 ; i < list.length; i++) { var xxx = list[i]; }
Copy after login
Copy after login

is equivalent to

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 some incorrect uses, please use them with caution:

1. Use wx:for-item directly, which will not loop out the list

 {{index}} {{item.name}} 
Copy after login
Copy after login

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

 {{item.id}}  {{items.name}}{{items.account}} 
Copy after login
Copy after login

The 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" which is used to define the variable of each element during the loop

If it is a one-dimensional array, Loop out as follows:

 {{index}} {{item.name}} 
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:

 {{item.id}}  {{items.name}}{{item.account}}   for (var i = 0 ; i < list.length; i++) { var xxx = list[i]; }
Copy after login
Copy after login

is equivalent to

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 some incorrect uses, please use them with caution:

1. Use wx:for-item directly, which will not loop out the list

 {{index}} {{item.name}} 
Copy after login
Copy after login

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

 {{item.id}}  {{items.name}}{{items.account}} 
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:

Summary of adding getter setter to JS

##How to use webpack react antd scaffolding in actual projects

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

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