遍历Array确实很好用,但遍历Map似乎不可行,是我用错了吗?
js代码如下:
Page({
data: {
array: [],
map_month_to_gifts: {},
array_month_to_gifts:[]
}
}
wxss代码如下:
<!--遍历数据-->
<view class="grid">
<view class="card short-card" wx:for="{{array_month_to_gifts}}" wx:for-item="giftItem">
<view> <text class="title">{{giftItem.month}}</text> </view>
<view> <text class="title">{{giftItem.gifts}}</text> </view>
</view>
</view>
<!--遍历Map,该Map是month到gift array的映射表-->
<view class="grid">
<view class='map_month_to_gifts' wx:for='{{map_month_to_gifts}}' wx:for-index="key">
<text>{{key}}:{{item}}</text>
</view>
</view>
可以呀
代码片段 https://developers.weixin.qq.com/s/9NB32Vm271iS
若认为该回答有用,给回答者点个[ 有用 ],让答案帮助更多的人
var obj_sample = new Object();
obj_sample["a"] = "0";
obj_sample["b"] = "1";
obj_sample["c"] = "2";
console.log('obj_sample: ',obj_sample)
var map_sample = new Map();
map_sample.set("a","0")
map_sample.set("b","1")
map_sample.set("c","2")
console.log('map_sample: ',map_sample)