求教:微信小程序里,怎么迭代map数据?
我的数据结构是这样子的:
cities: [{ 'A' : [{ id: 1, name: '爱河' }, { id: 2, name: '安口窑' }, { id: 3, name: '鞍山西' }, { id: 4, name: '阿拉山口' }] }, { 'B' : [{ id: 5, name: '包官营' }, { id: 6, name: '包头东' }, { id: 7, name: '宝鸡南' }] }, { 'C' : [{ id: 8, name: '长兴南' }, { id: 9, name: '漕河' }, { id: 10, name: '常州北' }] }] |
我代码里面怎么迭代这个数据?
我wxml里面这么写,我知道不对,但是又不知道应该怎么写?
< view class = "city-box" > < block wx:for = "{{cities}}" wx:for-item = "cityGroup" wx:key = "loop2" > < block wx:for = "{{cityGroup.keys}}" wx:for-item = "city" wx:key = "loop3" > < view class = "item" data-id = "{{city.id}}" >{{city.name}}</ view > </ block > </ block > </ view > |