javascript – Backbone – Collection.add()/ Collection.create()之间的区别?

前端之家收集整理的这篇文章主要介绍了javascript – Backbone – Collection.add()/ Collection.create()之间的区别?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我对两者之间的差异感到困惑.似乎Collection.create()(触发添加和同步事件)可以看作Collection.add()(fires add)和Model.save()(触发同步)的组合?

以上评估是否正确?我错过了什么?

解决方法

那就对了.这是一种捷径方法. Documentation states

create collection.create(attributes,[options])

Convenience to create
a new instance of a model within a collection. Equivalent to
instantiating a model with a hash of attributes,saving the model to
the server,and adding the model to the set after being successfully
created.

annotated source code

Create a new instance of a model in this collection. Add the model to
the collection immediately,unless wait: true is passed,in which case
we wait for the server to agree.

第二个描述更准确一点,因为只有传递{wait:true}才会在@R_476_301@时出现错误时不向模板中添加模型.

猜你在找的JavaScript相关文章