gpt4 book ai didi

javascript - 主干 - Collection.add()/Collection.create() 之间的区别?

转载 作者:数据小太阳 更新时间:2023-10-29 05:08:25 26 4
gpt4 key购买 nike

我对两者之间的差异感到很困惑。似乎 Collection.create() (触发 addsync 事件)可以看作是 Collection.add() (触发 add >) 和 Model.save()(触发 sync)?

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

最佳答案

没错。是一种捷径。 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} 的效果是在保存模型时出现错误时不会将模型添加到集合中。

关于javascript - 主干 - Collection.add()/Collection.create() 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12234646/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com