你会如何在这个结构中引用模型(Accord,CRV,Prius等)?
这是一个糟糕的结构,能够提取制作…然后使用make来获取模型…然后使用模型来获取选项?
这是一个糟糕的结构,能够提取制作…然后使用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.