0

我有这个json如下

[
 {
    "name":"River In 1", 
    "lat": 3.277801, 
    "lng": 101.681199,
    y: 55.11,
    drilldown: {
        data: [{"x":1.3722048e+12,"y":72.21},
                     {"x":1.3722057e+12,"y":67.84},
                     {"x":1.3722066e+12,"y":71.47},
                     {"x":1.3722075e+12,"y":71.22},
                     {"x":1.3722084e+12,"y":69.84},
                     {"x":1.3722093e+12,"y":65.19},
                     {"x":1.3722102e+12,"y":75.35},
                     {"x":1.3722111e+12,"y":75.32},
                     {"x":1.372212e+12,"y":70.31},
                     {"x":1.3722129e+12,"y":68.84},
                     {"x":1.3722138e+12,"y":66.19}]
    }   
},
{
    "name":"River In 2", 
    "lat": 3.272488, 
    "lng": 101.685491,
    y: 21.63,
    drilldown: {
        data: [{"x":1.3722048e+12,"y":72.21},
                     {"x":1.3722057e+12,"y":67.84},
                     {"x":1.3722066e+12,"y":71.47},
                     {"x":1.3722075e+12,"y":71.22},
                     {"x":1.3722084e+12,"y":69.84},
                     {"x":1.3722093e+12,"y":65.19},
                     {"x":1.3722102e+12,"y":75.35},
                     {"x":1.3722111e+12,"y":75.32},
                     {"x":1.372212e+12,"y":70.31},
                     {"x":1.3722129e+12,"y":68.84},
                     {"x":1.3722138e+12,"y":66.19}]
    }
},
{
    "name":"Ext River 1", 
    "lat": 3.288770, 
    "lng": 101.695583,
    y: 11.94,
    drilldown: {
            data: [{"x":1.3722048e+12,"y":72.21},
                         {"x":1.3722057e+12,"y":67.84},
                         {"x":1.3722066e+12,"y":71.47},
                         {"x":1.3722075e+12,"y":71.22},
                         {"x":1.3722084e+12,"y":69.84},
                         {"x":1.3722093e+12,"y":65.19},
                         {"x":1.3722102e+12,"y":75.35},
                         {"x":1.3722111e+12,"y":75.32},
                         {"x":1.372212e+12,"y":70.31},
                         {"x":1.3722129e+12,"y":68.84},
                         {"x":1.3722138e+12,"y":66.19}]
    }
},
{
    "name":"Ext River 2", 
    "lat": 3.284699, 
    "lng": 101.691960,
    y: 7.15,
    drilldown: {
            data: [{"x":1.3722048e+12,"y":72.21},
                         {"x":1.3722057e+12,"y":67.84},
                         {"x":1.3722066e+12,"y":71.47},
                         {"x":1.3722075e+12,"y":71.22},
                         {"x":1.3722084e+12,"y":69.84},
                         {"x":1.3722093e+12,"y":65.19},
                         {"x":1.3722102e+12,"y":75.35},
                         {"x":1.3722111e+12,"y":75.32},
                         {"x":1.372212e+12,"y":70.31},
                         {"x":1.3722129e+12,"y":68.84},
                         {"x":1.3722138e+12,"y":66.19}]
    }       
},
{
    "name":"Ext River 3", 
    "lat": 3.273645, 
    "lng": 101.690136,
    y: 2.14,
    drilldown: {
        data: [{"x":1.3722048e+12,"y":72.21},
                     {"x":1.3722057e+12,"y":67.84},
                     {"x":1.3722066e+12,"y":71.47},
                     {"x":1.3722075e+12,"y":71.22},
                     {"x":1.3722084e+12,"y":69.84},
                     {"x":1.3722093e+12,"y":65.19},
                     {"x":1.3722102e+12,"y":75.35},
                     {"x":1.3722111e+12,"y":75.32},
                     {"x":1.372212e+12,"y":70.31},
                     {"x":1.3722129e+12,"y":68.84},
                     {"x":1.3722138e+12,"y":66.19}]
    }
}
]

我指的是这个,没有解决方案能满足我对backboneJS的知识水平。

通常我曾经像 model.get('name') 那样得到它,但无法得到嵌套的项目/对象。任何人都可以帮助在“钻取”中获取项目

4

1 回答 1

1

由于drilldown直接设置为模型属性,因此您将首先使用model.get('drilldown'). 然后我们将其data作为一个属性,model.get('drilldown').data然后遍历该data属性,该属性是一个数组:

for (var i = 0, data = model.get('drilldown').data; i < data.length; i++) {
   // Each array element data[i] has a x and y property
   console.log(data[i].x, data[i].y);  // Logs 1.3722057e+12, 67.84
}
于 2013-09-11T06:04:39.843 回答