列表渲染
Page({
data: {
message: "hello 小程序",
list: ["html","Css","js"],
userList: [
{username: 'zmt', age: 35},
{username: 'tomcat', age: 20},
{username: 'jack', age: 30},
],
}
})
<view>
<view wx:for="{{list}}">
{{index}} {{item}}
</view>
<view wx:for="{{list}}"
wx:for-item="ele"
wx:for-index="eleIndex"
>
{{eleIndex}} {{ele}}
</view>
</view>
遍历对象数组
Page({
data: {
userList: [
{username: 'zmt', age: 35},
{username: 'tomcat', age: 20},
{username: 'jack', age: 30},
],
}
})
<view>
<view wx:for="{{userList}}">
{{index}}
用户名: {{item.username}}
年龄: {{item.age}}
</view>
</view>