BackboneJS:是否有可以绑定的默认事件列表?

发布于 2024-12-18 05:06:05 字数 307 浏览 0 评论 0原文

我知道我们可以在 Backbone.js 中创建自己的事件,例如

object.trigger('myEvent');

我还知道有一些默认事件,例如 changechange:

现在我想知道,是否有这些默认事件的列表? 我正在寻找当有人离开视图时触发的特定事件, 因此,无论是在删除视图时,还是在更改路线时, 我只是希望我不必侵入我自己的事件,并且查看这些事件的完整列表以供进一步参考也没什么坏处。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉月流沐 2024-12-25 05:06:05

更新 似乎该列表确实已经存在,正如 benoit 在上面的评论中所描述的那样,
它可以在这里找到... http://documentcloud.github.com/backbone/#FAQ -events


所以看来这样的列表不存在,好吧,我负责浏览带注释的源代码并在此处为可能需要它的每个人提供该列表。

我也将其作为社区维基帖子,因此我希望任何有需要的人都可以对其进行更新。无论新的 Backbone 版本是否带有额外的事件,或者我有什么问题,请随意编辑。

这是主干本身触发的事件列表:

  • change:

    使用model.set({, 'value'});后触发
    指示属性已更改。

  • 更改

    使用model.set({, 'value'});后触发
    以表明模型已更改。此火灾发生在您更改的任何属性上。

  • 销毁

    在销毁模型后触发,model.destroy({options});

  • 错误

    模型经过验证并且其中 1 个验证失败后触发,
    然而,如果传入一个特定的错误回调函数,该函数将
    代替 error 事件被执行。

    当您不向以下模型方法提供错误回调时也会触发:

    model.fetch();
    模型.save();
    模型.destroy();
    
  • 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:

    model.fetch();
    model.save();
    model.destroy();
    
  • reset

    fired when a collection is sorted through the collection.sort({options}); method
    also 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});

树深时见影 2024-12-25 05:06:05

您正在查找的特定事件不存在,但可以轻松添加。

Backbone.View.prototype.remove = function() {
  $(this.el).remove();
  this.trigger('remove', this);
  return this;
}

如果您使用路由器,还有内置的“导航”事件。

The particular event you are looking for does not exist, but it can be added easily.

Backbone.View.prototype.remove = function() {
  $(this.el).remove();
  this.trigger('remove', this);
  return this;
}

There is also a 'navigate' event built in, if you are using the Router.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文