Backbone.js 主干V1.0.0中的更改事件触发器
我下载了最新的主干V1.0.0,与V0.9.2相比发现了一些奇怪的问题Backbone.js 主干V1.0.0中的更改事件触发器,backbone.js,requirejs,Backbone.js,Requirejs,我下载了最新的主干V1.0.0,与V0.9.2相比发现了一些奇怪的问题 TodosCollection.on('add', this.addOne, this); TodosCollection.on('reset', this.addAllTodos, this); TodosCollection.on('change:completed', this.filterOne, this); TodosCollection.on("f
TodosCollection.on('add', this.addOne, this);
TodosCollection.on('reset', this.addAllTodos, this);
TodosCollection.on('change:completed', this.filterOne, this);
TodosCollection.on("filter", this.filterAll, this);
TodosCollection.on('all', this.render, this);
向集合添加新内容后,在V0.9.2中,只有以下三序列事件触发:
add
change
sync
但是在V1.0.0中,除了上述三个
change:cid
"change:attributes"
"change:collection"
"change:_changing"
.....
这么多事件触发
模型
实际上在模型中没有这些触发事件,那么为什么会发生这种情况呢 了解版本之间的更改可能很有用。也是。你提到的只是内置事件,没有什么不对。稍微研究/阅读一下主干网的文档(使用主干网时非常经典的行为)就会告诉你这一点。
如果我在你的问题中遗漏了一点,请随时告诉我。非常感谢,我已经检查了文档,但没有找到明确的解释,所以请发布此问题!您的解释如下:这些是在属性更改时自动触发的内置事件:“更改:属性”。
define([
'lodash',
'backbone'
], function (_, Backbone) {
var TodoModel = Backbone.Model.extend({
defaults : {
title : '',
completed : false,
order : 0
},
settings : {
validation : {
rules : {
title : {
"required" : true,
"min" : 5
}
}
}
},
toggle : function () {
this.save({
completed : !this.get('completed')
});
}
});
return TodoModel;
});