Backbone - 聆听 2 个模型的最佳方式是什么?
Backbone - What is the best way to listen to 2 models?
我正在做一个项目,我很好奇什么是收听在同一功能中使用的 2 个对象的最佳方式?
例如:
this.model1 = someModel();
this.model2 = someModel();
this.listenTo(this.model1, "sync", this.someFunction); // how can I get listenTo to listen for both changes before calling the function?
this.listenTo(this.model2, "sync", this.someFunction);
someFunction: function() {
this.sumValue = (this.model1.get('value') + this.model2.get('value));
}
感谢您的帮助!
创建一个基础模型并继承您的其他模型:
var DataModel = Backbone.Model.extend({
// ToDo
});
var FileModel = DataModel.extend({
// ToDo
});
var FolderModel = DataModel.extend({
// ToDo
});
使集合的模型类型与基础模型相同:
var DataCollection = Backbone.Collection.extend({
model: DataModel
});
我正在做一个项目,我很好奇什么是收听在同一功能中使用的 2 个对象的最佳方式?
例如:
this.model1 = someModel();
this.model2 = someModel();
this.listenTo(this.model1, "sync", this.someFunction); // how can I get listenTo to listen for both changes before calling the function?
this.listenTo(this.model2, "sync", this.someFunction);
someFunction: function() {
this.sumValue = (this.model1.get('value') + this.model2.get('value));
}
感谢您的帮助!
创建一个基础模型并继承您的其他模型:
var DataModel = Backbone.Model.extend({
// ToDo
});
var FileModel = DataModel.extend({
// ToDo
});
var FolderModel = DataModel.extend({
// ToDo
});
使集合的模型类型与基础模型相同:
var DataCollection = Backbone.Collection.extend({
model: DataModel
});