我想比较我收藏的模型属性并将其存储到新模型中。
Collection:
Model1:
Apple: 1
Banana: 0
Orange: 0
Status: 1254869
Model2:
Apple: 0
Banana: 1
Orange: 1
Status: null
输出应该是:
ModelResult:
Apple: 1
Banana: 1
Orange: 1
Status: 1254869
有任何想法吗?
我手动做
ModelResult = collection.at(0);
collection.each( function(model){
if(model.get("Apple") != 0){
ModelResult.set({Apple: model.get("Apple")});
}
if(model.get("Banana") != 0){
ModelResult.set({Apple: model.get("Banana")});
}
if(model.get("Orange") != 0){
ModelResult.set({Apple: model.get("Orange")});
}
if(model.get("Status") != ""){
ModelResult.set({Apple: model.get("Status")});
}
});
笔记:
是否也可以消除0
或null
重视ModelResult
?
谢谢你。