addyosmani / addyosmani/backbone-fundamentals
Collections {merge: true} unclear
- 主要语言
- Rich Text Format
- 星标
- 9.2k
- 派生
- 1.4k
- PR 合并指标
- 30 天内没有已合并 PR
描述
> Also note that when using add() on a collection, passing {merge: true} causes duplicate models to have their attributes merged in to the existing models, instead of being ignored.
```
var items = new Backbone.Collection;
items.add([{ id : 1, name: "Dog" , age: 3}, { id : 2, name: "cat" , age: 2}]);
items.add([{ id : 1, name: "Bear" }], {merge: true });
items.add([{ id : 2, name: "lion" }]); // merge: false
console.log(JSON.stringify(items.toJSON()));
// [{"id":1,"name":"Bear","age":3},{"id":2,"name":"cat","age":2}]
```
What exactly is a "duplicate model"? It seems to be where they have the same id, but I'm not sure.
And does `items.add([{ id : 2, name: "lion" }]); // merge: false` log out some sort of error?
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。