我試圖從一個json文件解析數據到一個集合視圖,該文件對每個數據組都有數字鍵。該JSON看起來是這樣的:Backbone Js - 解析數據問題
{
"0": {
"artifact_id": "36",
"timestamp": "2013-08-20 11:59:00",
"modified": "2013-08-20 11:59:00",
"text": "Why did the last one duplicate? I don't think I clicked it twice...",
"author_desc": "",
"object_type": "artifact",
"comments": []
},
"1": {
"artifact_id": "35",
"timestamp": "2013-08-20 11:57:51",
"modified": "2013-08-20 11:57:51",
"text": "This is a new artifact for a new day.",
"author_desc": "",
"object_type": "artifact",
"comments": []
},
"2": {
"artifact_id": "34",
"timestamp": "2013-08-20 11:57:50",
"modified": "2013-08-20 11:57:50",
"text": "This is a new artifact for a new day.",
"author_desc": "",
"object_type": "artifact",
"comments": []
}
}
我怎樣寫一個模型解析採取的條目(0,1,2 ...等),從數據中的每個模型的每一個?
這是我收集,從下面凱西建議此外,但它似乎並沒有被運行的解析方法:
var FriendCollection = Backbone.Collection.extend({
model: FriendModel,
parse: function(data) {
console.log('running parse');
return _.map(data, _.identity);
}
});
var friendCollection = new FriendCollection();
friendCollection.reset(friendjson);
collection.parse僅在從服務器進行提取時運行。 http://backbonejs.org/#Collection-parse –