For a list of data
- wxml
<view wx:for="{{dataList}}">{{index}}-{{item}}</view>
We can see that the above code default to the index and item if we want to modify their own words with the following code
<view wx:for="{{dataList}}" wx:for-index="idx" wx:for-item="xxxx">{{idx+1}}-{{xxxx}}</view>
- js
Page({ data: { dataList: [ " mask " , " goggles " , " disinfectant " ] }, })
For data dictionary
- wxml
<view wx:for="{{userInfo}}">{{index}}-{{item}}</view>
- js
Page({ data: { userInfo:{ name: ' Xiaoqiang ' , age:18 } }, })