我是Backbone.js的新手
我有一个JSON,如图所示!我看到一些关于Backbone-relational的答案,但仍然没有明白这一点!
如何将此JSON转换为Backbone.js集合/模型?
我用代码更新,但它不像预期的那样工作!我做的时候看不到模特:
我的结构是:
[0]:是模型的集合
[clefs] + ... + [Rest]:是模型的集合
(谱号)=> [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});
}
});
Run Code Online (Sandbox Code Playgroud)
这也帮助了我!
