1.定义
wx:for 这个是正常的循环,没什么可说的。
wx:for-item=‘变量名(随便起的)’ 它是指定循环数据当前的变量名,可以通过 {{变量名.属性}} 展示数组的元素。
wx:for-index=‘变量名(随便起)’,它是指向当前元素的下标名,可以在其他事件中定义自定义事件(data-xxx='{{变量名}}',,该自定义属性可以在参数e下面打印出来)获取该下标。
2.示例:
代码wxml:
<view class='lightList' wx:for='{{lightList}}' wx:key='index' wx:for-item="light">
<view class='top'>
<view class='star'>
<image src='/images/star.png' style='height:25px;width:25px'></image>
</view>
<view class='title'>{{light.name}}</view>
<view class='time'>{{light.time}}</view>
</view>
<view class='brief'>
简述:{{light.brief}}
</view>
<view class='imageList'>
<view class='image' wx:for='{{light.imageList}}' wx:key='index' wx:for-item="image">
<image src='{{image}}' style='height:200rpx;width:200rpx' data-image='{{light.imageList}}' data-index='{{index}}' bindtap='previewImage'></image>
</view>
</view>
</view>
js:
*/
data: {
lightList: [{
name: "从技术粗糙表面",
imageList: ["/images/details.png", "/images/details.png", "/images/details.png"],
time: "2018.10.02 12:10:22",
brief: "将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。"
},
{
name: "长十九年",
imageList: ["/images/details.png", "/images/details.png"],
time: "2018.10.02 12:10:22",
brief: "将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。"
},
{
name: "长十九年",
imageList: ["/images/details.png", "/images/details.png"],
time: "2018.10.02 12:10:22",
brief: "将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。"
},
{
name: "长十九年",
imageList: ["/images/details.png", "/images/details.png"],
time: "2018.10.02 12:10:22",
brief: "将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。"
},
],
},
previewImage: function(e) {
console.log(e)
},
结果: