主干js中的模型更改事件顺序
是否保证“change:property”事件始终在“change”事件之前触发? 这是一个例子:
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"); });
是否保证绑定到“change”的函数将最后被触发?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短回答:是的
查看源代码,是的,
individual:changes
在循环中触发,之后,如果有任何更改,主change
事件将火。如果您传递silent: true
,这些都不会触发。各个更改事件触发的顺序取决于传递给
.set()
的属性的顺序。Short answer: yes
Looking at the source code, yes the
individual:changes
are fired in the loop, and after that, if there was any change, the mainchange
event will fire. None of these will fire if you passedsilent: true
.The order of the individual change events firing depends on the order of the attributes passed to
.set()
.