型号更改事件顺序骨干JS [英] Model change event order in backbone js

查看:136
本文介绍了型号更改事件顺序骨干JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是保证的变​​化:财产事件总是解雇的的变事件?
下面是一个例子:

Is it guaranteed that 'change:property' events are always fired before 'change' events? Here is an example:

MyModel = Backbone.Model.extend({
    property1: 'value1',
    property2: 'value2'
});

var myModel = new MyModel();
myModel.bind('change:property1', function () { alert("change pty1"); })
       .bind('change', function () { alert("change"); })
       .bind('change:property2', function () { alert("change pty2"); });

能够保证所有的绑定到改变的功能将被解雇最后?

Is it guaranteed that the function bound to 'change' will be fired last?

推荐答案

简短的回答:是的。

查看源$ C ​​$ C,是在个人:修改在循环被解雇,之后,如果有任何变化,主要的变更事件将触发。这一切都不会火,如果你通过了沉默:真正的

Looking at the source code, yes the individual:changes are fired in the loop, and after that, if there was any change, the main change event will fire. None of these will fire if you passed silent: true.

个别更改事件触发的顺序取决于传递给的.set()

The order of the individual change events firing depends on the order of the attributes passed to .set().

这篇关于型号更改事件顺序骨干JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆