主干JS解析集合的json属性';s模型

主干JS解析集合的json属性';s模型,json,parsing,backbone.js,collections,Json,Parsing,Backbone.js,Collections,我在将json解析为模型时遇到问题 以下是JSON: [ { "name": "Douglas Crockford", "email": "example@gmail.com", "_id": "50f5f5d4014e045f000002", "__v": 0, "items": [ { "cena1": "Cena1", "cena2": "Cena2", "cen

我在将json解析为模型时遇到问题

以下是JSON:

[
{
    "name": "Douglas Crockford",
    "email": "example@gmail.com",
    "_id": "50f5f5d4014e045f000002",
    "__v": 0,
    "items": [
        {
            "cena1": "Cena1",
            "cena2": "Cena2",
            "cena3": Cena3,
            "cena4": "Cena4",
            "cena5": "Cena5",
            "cena6": Cena6,
            "_id": "50ee3e782a3d30fe020001"
        }
    ]
}
]

我需要一个模型具有如下“items”属性:

cena = new Model({ 
           cena1: "Cena1", 
           cena2: "Cena2",
           ... 
});
我所尝试的:

var cenaCollection = new Backbone.Collection.extend({
   model: Cenas,
   url: '/orders',

   parse: function (response) {
      return this.model = response.items;
   }

});
然后我创建了集合和获取的新实例,但得到的“response.items”总是“undefined”:|


提前谢谢

parse函数应返回要在模型上设置的属性哈希(请参阅)。因此,您只需要:

parse: function (response) {
   return response[0].items;
}

@asirgado我刚刚注意到您的JSON似乎被包装在一个数组中——对吗?如果是这样的话,您将需要
响应[0]。项
…?只要尝试一下,它就可以按我的需要工作!谢谢如果我在数组中获得更多的“项”,它会工作吗?谢谢