微信小程序--wx:for
2017-07-02 10:32
495 查看
wx:for 与block标签
wxml:
注意:当渲染的列表中有嵌套的标签或多个同级标签,只能用block做容器
另一重要应用点:
wx:for循环生成的列表,可以将index赋值给标签的data-xxx属性,js通过e.currentTarget.dataset.xxx或e.target.dataset.xxx获取index的值
wxml:
<block class="searchListContent" wx:for="{{songInfo}}"> <view class="centerFather"> <view class="{{(index%2)?'searchListSong':'searchListSong1'}}"> <view bindtap="ifPlay" class="searchListSongNText">{{item.songN}}</view> <view class="searchListSingerText">{{item.singer}}</view> </view> </view> </block>js:
page({ data:{ "songInfo": { "0": { "songN": "歌名", "singer": "歌手" }, "1": { "songN": "你给我听好1", "singer": "陈奕迅" }, "2": { "songN": "你给我听好2", "singer": "陈奕迅" }, "3": { "songN": "你给我听好5", "singer": "陈奕迅" }, "4": { "songN": "你给我听好3", "singer": "陈奕迅" }, "5": { "songN": "你给我听好4", "singer": "陈奕迅" }, "6": { "songN": "你给我听好5", "singer": "陈奕迅" }, "7": { "songN": "你给我听好3", "singer": "陈奕迅" }, "8": { "songN": "你给我听好4", "singer": "陈奕迅" }, "9": { "songN": "你给我听好4", "singer": "陈奕迅" } } } })效果:
注意:当渲染的列表中有嵌套的标签或多个同级标签,只能用block做容器
另一重要应用点:
wx:for循环生成的列表,可以将index赋值给标签的data-xxx属性,js通过e.currentTarget.dataset.xxx或e.target.dataset.xxx获取index的值
相关文章推荐
- 微信小程序 Now you can provide attr "wx:key" for a "wx:for" to improve performance.
- 微信小程序 wx:for循环和数组内部元素的增加
- 微信小程序-wx:for 循环列表
- 微信小程序----wx:key(Now you can provide attr "wx:key" for a "wx:for" to improve performance.)
- 微信小程序 wx:for 点击事件
- 微信小程序判断wx:if wx:for template
- 微信小程序(wx:for)遍历对象
- 微信小程序循环:Wx:for
- 【微信小程序】wx:for的使用
- 微信小程序 列表渲染 wx:for
- 微信小程序数据使用wx:for循环展示
- 微信小程序的wx:for,wx:for-items,wx:for-item,wx:key等的关系及正确使用
- 微信小程序wx:for和wx:for-item的用法详解
- 微信小程序开发warning: Now you can provide attr "wx:key" for a "wx:for" to improve performance
- 微信小程序-wx:for 循环列表
- 微信小程序之wx:for循环输出及require引入外部数据
- 微信小程序wx:for循环列表渲染
- [微信小程序]控制台弹出 warning: Now you can provide attr "wx:key" for a "wx:for" to improve performance
- 微信小程序 wx:for的使用实例详解