vue 遍历数组和对象

时间:2018-12-29 15:15:23   收藏:0   阅读:1650

一,遍历数组

wxml布局

<view class=‘common_tags_item‘ wx:for="{{filter_grade_list}}" wx:key="this" bindtap=‘selectFilterGrade‘ data-hi="{{index}}"  style="background:{{filter_grade===index ? ‘#FFF5F5‘: ‘#F2F2F2‘}};border-width:{{filter_grade===index?1:0}}px;">
       <text>{{item.text}}</text>
</view>

js代码

for(var i=0;i<arr.length;i++){
    //....
}

二,遍历对象(字典)

wxml布局

<view class=‘functional-module-item‘ wx:for="{{commonMenu}}" wx:key="this" bindtap=‘myCommonClick‘ data-hi="{{item.url}}"
       <text>{{item.text}}</text>
</view>

js代码

for(var p in myJson){ //遍历json对象的每个key/value对,p为key
   alert(p + " " + myJson[p]);
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!