我有一组运算符,运算符视图应该在svg上绘制运算符容器。但我得到最后一行的TypeError:this.model is undefined
。为什么我收到此错误?
var Operators = new DataMapper.Collections.Operators(); //Operators is a collection defined previously
var concatModel = new DataMapper.Models.Operator({title: "Concat", id: "concat" + new Date().getTime(), inputCount: 2, outputCount: 1});
var concatView = new DataMapper.Views.OperatorView({model: concatModel});
Operators.add([concatModel]);
更新:扩展了代码 - 我使用的是backbone_1.3.3
DataMapper.Collections.Operators = Backbone.Collection.extend({
model: DataMapper.Models.Operator
});
DataMapper.Views.OperatorPanelView = Backbone.View.extend({
el: "#op-panel",
events: {
"click #concat-op-btn": "addConcatOp"
},
addConcatOp: function () {
var concatModel = new DataMapper.Models.Operator({title: "Concat", id: "concat" + new Date().getTime(), inputCount: 2, outputCount: 1});
var concatView = new DataMapper.Views.OperatorView({model: concatModel});
//console.log(concatModel);
DataMapper.Operators.add([concatModel]); //where error occurs
}
});
DataMapper.Views.CanvasView = Backbone.View.extend({
el: "#canvas",
params: {
inputStartX: 40,
inputStartY: 40,
outputStartX: 800,
outputStartY: 40,
elementWidth: 170,
elementHeight: 20
},
initialize: function () {
DataMapper.Operators = new DataMapper.Collections.Operators(); //initialize a collection
new DataMapper.Views.LoadFileView();
new DataMapper.Views.OperatorPanelView();
}
});
new DataMapper.Views.CanvasView();