小程序学习之列表循环
wxml代码:
注意:wx:key=“index” 写上,不然会提示错误,虽然不影响代码运行,还是写上吧
<view class="item-list">
<view class="item-list-box" wx:for="{{itemList}}" wx:key="index" wx:for-item="item">
<view class="item-top">
<view class="pic">
<image src="{{item.pic}}"></image>
</view>
<view class="info">
<view class="font28">{{item.name}}
<text class="tip">{{item.lable}}</text>
</view>
<text class="font26">{{item.store}}</text>
</view>
</view>
<view class="item-pic">
<view class="pic-list" wx:for="{{item.imgs}}" wx:key="index" wx:for-item="img">
<image src="{{img}}"></image>
</view>
</view>
</view>
</view>
这里店铺图片是for循环里面的for循环,要注意
js代码(page的data里面)
itemList:[
{
'pic':'../../images/index/pic.png',
'name':'张先生',
'store':'盛世江南店',
'lable':'旗舰店',
'imgs': [
'../../images/index/img.png',
'../../images/index/img2.png',
'../../images/index/img.png'
]
},
{
'pic': '../../images/index/pic.png',
'name': '李先生',
'store': '海上五月花店',
'lable': '旗舰店',
'imgs': [
'../../images/index/img.png',
'../../images/index/img2.png',
'../../images/index/img.png'
]
},
{
'pic': '../../images/index/pic.png',
'name': '周先生',
'store': '四季花城店',
'lable': '旗舰店',
'imgs': [
'../../images/index/img2.png',
'../../images/index/img.png',
'../../images/index/img2.png'
]
},
]
效果如下: