收藏
回答

急!!微信小程序如何迭代map数据结构?

问题模块
API和组件

我现在有这样的一个数据结构:

this.data.testArray = [{
            'bed_type': [{
                code: 'QUEEN,KING',
                groupName: '床型',
                lvl: 10,
                name: '大床',
                type: 1
            }, {
                code: 'DOUBLE',
                groupName: '床型',
                lvl: 20,
                name: '双床',
                type: 1
            }, {
                code: 'THREE',
                groupName: '床型',
                lvl: 30,
                name: '三人/家庭房',
                type: 1
            }]
        }, {
            'breakfast': [{
                code: 'Y|Y',
                groupName: '早餐',
                lvl: 10,
                name: '含早餐',
                type: 0
            }, {
                code: 'Y|N',
                groupName: '早餐',
                lvl: 20,
                name: '单人早餐',
                type: 0
            }, {
                code: 'N|N',
                groupName: '早餐',
                lvl: 30,
                name: '双份早餐',
                type: 0
            }]
        }, {
            'pay': [{
                code: 'SPOTPAY',
                groupName: '支付',
                lvl: 20,
                name: '到店支付',
                type: 0
            }, {
                code: 'ONLINEPAY',
                groupName: '支付',
                lvl: 30,
                name: '线上支付',
                type: 0
            }]
        }, {
            'cancel': [{
                code: 'CACELFREE',
                groupName: '其他',
                lvl: 10,
                name: '免费取消',
                type: 0
            }]
        }]

我wxml里面该如何迭代这个map,数组的每一项key,我取不到啊

最后一次编辑于  2017-07-11  (未经腾讯允许,不得转载)
回答关注问题邀请回答
收藏

1 个回答

  • 胖子
    胖子
    2017-07-11

    在交给wxml 前先处理下数据吧,

    如果要在一个遍历里面做得很话要先把数据扁平化,用一个统一的key 来表示数组每一项的key, 值为 这个 key,

    可以都叫 name,那你的结构就是

    [ { name: 'bed_type', items: [ xxx ] }, { name: 'breakfast', items: [ xxx ] }  ]



    2017-07-11
    赞同
    回复