BackboneJS:是否有可以绑定的默认事件列表?
我知道我们可以在 Backbone.js 中创建自己的事件,例如
object.trigger('myEvent');
我还知道有一些默认事件,例如 change
或 change:
现在我想知道,是否有这些默认事件的列表? 我正在寻找当有人离开视图时触发的特定事件, 因此,无论是在删除视图时,还是在更改路线时, 我只是希望我不必侵入我自己的事件,并且查看这些事件的完整列表以供进一步参考也没什么坏处。
I know we can create our own events in Backbone.js like
object.trigger('myEvent');
I also know there are some default events like the change
or change:<attributename>
now i'm wondering, is there a list somewhere of these default events?
i am looking for a specific event that triggers when someone navigates away from a view,
so either in the removing of the view, or perhaps when a route is changed,
I just hope i don't have to hack in my own event and it can't hurt to see a full list of these events for further reference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新 似乎该列表确实已经存在,正如 benoit 在上面的评论中所描述的那样,
它可以在这里找到... http://documentcloud.github.com/backbone/#FAQ -events
所以看来这样的列表不存在,好吧,我负责浏览带注释的源代码并在此处为可能需要它的每个人提供该列表。
我也将其作为社区维基帖子,因此我希望任何有需要的人都可以对其进行更新。无论新的 Backbone 版本是否带有额外的事件,或者我有什么问题,请随意编辑。
这是主干本身触发的事件列表:
change:
使用
model.set({, 'value'});后触发
指示属性已更改。
更改
使用
model.set({, 'value'});后触发
以表明模型已更改。此火灾发生在您更改的任何属性上。
销毁
在销毁模型后触发,
model.destroy({options});
错误
模型经过验证并且其中 1 个验证失败后触发,
然而,如果传入一个特定的错误回调函数,该函数将
代替
error
事件被执行。当您不向以下模型方法提供错误回调时也会触发:
reset
通过
collection.sort({options});
方法对集合进行排序时触发当明确要求通过
collection.reset(models, {options});
重置集合时也会触发
add
将模型添加到集合时触发
collection.add(models, {options});
删除
从集合中删除模型时触发...
collection.remove(models, {options});
update seems like the list did exist already, as benoit describes in the comment above,
it can be found here... http://documentcloud.github.com/backbone/#FAQ-events
so it seems such a list does not exist, well, i took it upon me to go through the annotated source and present the list here for everyone who might ever need it.
i do also make this a community wiki post, so i hope it will be updated by any of you who feel the need to. whether a new Backbone version comes with extra events or i've got something wrong, feel free to edit.
here goes the list of events triggered by backbone itself:
change:<attributename>
fired after using
model.set({<attributename>, 'value'});
to indicate the attribute was changed.
change
fired after using
model.set({<attributename>, 'value'});
to indicate the model was changed. this fire's on any attribute you change.
destroy
fires after you destroy a model,
model.destroy({options});
error
fires after a model is validated and 1 of the validations fails,
if however a specific error callback function is passed in, that one will
be executed instead of the
error
event.also fires when you do NOT give an error callback to the following model methods:
reset
fired when a collection is sorted through the
collection.sort({options});
methodalso fired when specifically asking to reset a collection through
collection.reset(models, {options});
add
fired when a model is added to a collection
collection.add(models, {options});
remove
fired when a model is removed from a collection...
collection.remove(models, {options});
您正在查找的特定事件不存在,但可以轻松添加。
如果您使用路由器,还有内置的“导航”事件。
The particular event you are looking for does not exist, but it can be added easily.
There is also a 'navigate' event built in, if you are using the Router.