我主要想知道选项(第一个之后的任何模型)是否通过引用传递。
第一个通过的模型:
App.testModel = Backbone.Model.extend({
defaults: {
passBy: "value"
}
});
作为选项传递的第二个模型:
App.testModelOptions = Backbone.Model.extend({
defaults: {
passBy: "value"
}
});
将两个模型的 passBy 设置为“参考”的视图
App.TestView = Backbone.View.extend({
initialize: function() {
this.model1 = this.model;
this.model2 = this.options.model2;
this.model1.set({passBy: "reference"});
this.model2.set({passBy: "reference"});
}
});
主要的:
// Router
App.AppRouter = Backbone.Router.extend({
routes:{
"":"test"
}
test:function() {
this.testModel = new App.testModel();
this.testModel2 = new App.testModelOptions();
this.testView = new App.TestView({model: this.testModel, model2: this.testModel2});
console.log(this.testModel.get("passBy"));
console.log(this.testModel2.get("passBy"));
}
});