引用javascript对象文字数组

前端之家收集整理的这篇文章主要介绍了引用javascript对象文字数组前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
你会如何在这个结构中引用模型(Accord,CRV,Prius等)?
这是一个糟糕的结构,能够提取制作…然后使用make来获取模型…然后使用模型来获取选项?
var cars = [
    {
        "makes"   : "Honda","models"   : [
            {'Accord' : ["2dr","4dr"]},{'CRV'    : ["2dr","Hatchback"]},{'Pilot'  : ["base","superDuper"] }
        ]
    },{
        "makes"   : "Toyota","models"  : [
            {'Prius'   : ["green","reallyGreen"]},{'Camry'   : ["sporty","square"]},{'Corolla' : ["cheap","superFly"] }
        ]
    }
];

谢谢

解决方法

结构:
var cars = [
    { name: 'Honda',models: [
                { name: 'Accord',features: ['2dr','4dr'] },{ name: 'CRV','Hatchback'] },{ name: 'Pilot',features: ['base','superDuper'] }
        ]},{ name: 'Toyota',models: [
                { name: 'Prius',features: ['green','superGreen'] },{ name: 'Camry',features: ['sporty','square'] },{ name: 'Corolla',features: ['cheap','superFly'] }
        ]}
];

我写了关于遍历和其他一切here.

猜你在找的JavaScript相关文章