我对 Backbone.js 比较陌生
我有一个如图所示的JSON!我看到了一些与骨干关系相关的答案,但仍然不明白这一点!
如何将此JSON转换为 Backbone.js 集合/模型?
我用代码更新,但它不像预期的那样工作!当我这样做时,我看不到模型:
我的结构是:
[0] :是模型的集合
[谱号] + ... + [休息] : 是模型的集合
(谱号) => [0] + ... + [9] : 是模型(标题包含一个字符串,路径也是)
非常感谢!!
编辑(10.01.12):
我的解决方案:
window.initModel = Backbone.Model.extend({
defaults: {
"title": "",
"path": ""
}
});
window.CustomCollection = Backbone.Collection.extend({
model: initModel
});
window.Init = Backbone.Model.extend({
url : function(){
return "/api/data.json"
},
parse: function(response) {
clefs = new CustomCollection();
clefs.add(response.clefs);
this.set({clefs: clefs});
.....
rests = new CustomCollection();
rests.add(response.rests);
this.set({rests: rests});
}
});
这也帮助了我!