Home>Article>WeChat Applet> Detailed explanation of WeChat applet for loop

Detailed explanation of WeChat applet for loop

高洛峰
高洛峰 Original
2017-01-09 10:56:57 4609browse

1.wx:for

Use the wx:for control attribute on the component to bind an array, and the component can be repeatedly rendered using the data of each item in the array. By default, the subscript variable name of the current item in the array defaults to index, and the variable name of the current item in the array defaults to item. Examples are as follows:

wxml file:

 {{index}}: {{item:one}}  js文件: Page({ items:[{ one: "test1", },{ one: "test2" }] })

You can use wx:for-item to specify the variable name of the current element of the array

You can use wx:for-index to specify the variable name of the current index of the array, for example:

wxml file:

 {{id}}: {{name.one}}  下面是一个九九乘法表事例:    {{i}}*{{j}} = {{i * j}}   

2. block wx:for

wx:for is used on the 935bb15358aeeb18747ba360a3e4ab1a tag to render a structure block containing multiple nodes. For example:

  {{index}}:   {{item}}  

The renderings are as follows:

微信小程序 for 循环详解

Thanks for reading, I hope this helps everyone, and thank you for your support of this site!

For more articles related to the detailed explanation of the WeChat applet for loop, please pay attention to 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