Home > WeChat Applet > Mini Program Development > WeChat Mini Program Tutorial List Rendering

WeChat Mini Program Tutorial List Rendering

黄舟
Release: 2017-01-16 15:04:57
Original
1731 people have browsed it

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.

The subscript variable name of the current item of the default array defaults to index, and the variable name of the current item of the array defaults to item

<view wx:for="{{items}}">  
 {{index}}: {{item.message}}  
</view>
Copy after login
Page({  
 items: [{  
 message: &#39;foo&#39;,  
 },{  
 message: &#39;bar&#39;  
 }]  
})
Copy after login

Use wx:for-item to specify the variable name of the current element of the array

Use wx:for-index to specify the variable name of the current subscript of the array:

<view wx:for="{{array}}" wx:for-index="idx" wx:for-item="itemName">  
 {{idx}}: {{itemName.message}}  
</view>
Copy after login

wx:for can also be nested. Below is a multiplication table

<view wx:for="{{[1, 2, 3, 4, 5, 6, 7, 8, 9]}}" wx:for-item="i">  
 <view wx:for="{{[1, 2, 3, 4, 5, 6, 7, 8, 9]}}" wx:for-item="j">  
 <view wx:if="{{i <= j}}">  
  {{i}} * {{j}} = {{i * j}}  
 </view>  
 </view>  
</view>
Copy after login

block wx:for

Similar to block wx:if, wx:for can also be used on the tag to render a structure block containing multiple nodes. For example:

<block wx:for="{{[1, 2, 3]}}">  
 <view> {{index}}: </view>  
 <view> {{item}} </view>  
</block>
Copy after login

The above is the content of the list rendering of the WeChat applet tutorial. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


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