Javascript 主干重新格式化模型
你好,我有一个主干模型,看起来像这样Javascript 主干重新格式化模型,javascript,backbone.js,backbone-model,Javascript,Backbone.js,Backbone Model,你好,我有一个主干模型,看起来像这样 Project {cid: "c2", attributes: Object, _changing: false, _previousAttributes: Object, changed: Object…} _changing: false _pending: false _previousAttributes: Object attributes: Object brief: ""
Project {cid: "c2", attributes: Object, _changing: false, _previousAttributes: Object, changed: Object…}
_changing: false
_pending: false
_previousAttributes: Object
attributes: Object
brief: ""
colour: "#2a5563"
created: "2014-04-22 16:15:57"
created_by: "Me"
creator_id: "14"
dates: Array[1]
files: Array[8]
items: Array[7]
progress: "0"
project_id: "7692"
project_name: "Rendering on new task"
status: "1"
tasks: Array[1]
__proto__: Object
changed: Object
cid: "c2"
__proto__: ctor
items数组需要一个模型,items数组当前由多个对象组成,每个对象都有一个名为subitems的属性-该属性是一个数组,但我认为它需要是一个集合,事实上,除item数组之外的每个think都需要是集合
执行此操作的最佳方法是什么?您可以将项目设置为具有一组项目的主干集合。使用
var itemsArray = project.get('items');
itemsArray.each(function (item) {
item = new Item();//collection/model.
});
var items = new Items(itemsArray);//Items is a backbone collection.
project.set('items', items);
并且可以作为
project.get('items');
这样,您可以嵌套任意数量的集合/模型