如何避免在骨干网中添加新模型时触发变更事件

How to avoid triggering change event when new model is added into collection in backbone?

本文关键字:事件 模型 骨干网 何避免 添加 新模型      更新时间:2023-09-26

现在我已经定义了一个集合,并绑定了添加和更改事件侦听器,但是当添加新模型时,将触发更改事件。

collection.bind('add',addMethod);
collection.bind('change',changeMethod);

如何避免触发变更事件?

正如在注释中提到的,当您向集合中添加某些内容时,请为该函数调用添加silent-option。查看Backbonejs参考以获取更多信息。

collection.add(someModel, {silent: true});