0
我在視圖中創建blockView的實例並將模型作爲參數傳遞。但是當我運行它會給我錯誤「TypeError:不能將undefined轉換爲對象」。我試圖追查這個錯誤,但我無法得到。任何人plz。 PLZ找到下面的代碼骨幹視圖問題
var DCSSPACE = DCSSPACE || {};
$(document).ready(function(){
WorkSpace = new draw2d.Workflow("canvasdiv");
collection = new DCSSPACE.collection.collection();
view = new DCSSPACE.view.view({WorkSpace : WorkSpace, collection : collection});
});
DCSSPACE.view = function(){
var uniqueid = 1, blockCounter = 0;
var view = Backbone.View.extend({
el : $("#canvasdiv"),
views : {},
initialize : function() {
console.log("View");
this.collection.bind("add", function(m, temp, data){
console.log(data.evt);
//Here i am getting error "TypeError: can't convert undefined to object"
this.views[m.cid] = new blockView({data : data, model : m, id : "view_" + m.cid});
},this);
this.collection.bind("remove", function(m){
this.views[m.cid].remove();
delete this.views[m.cid];
}, this);
this.render(WorkSpace);
},
render : function(WorkSpace) {
$("#sidediv").accordion();
this.disableSelection(document.body);
var menu = new draw2d.FlowMenu(WorkSpace);
WorkSpace.addSelectionListener(menu);
var toolwindow = new draw2d.Toolbox();
WorkSpace.setToolWindow(toolwindow);
toolwindow.setPosition(0,0);
$(".btn").draggable({
helper : "clone",
stop : function(event, ui) {
var data = {
id : this.id,
evt : event.originalEvent,
};
if(event.originalEvent.pageX >= 220) {
var m = new DCSSPACE.model.FunctionBlockModel();
collection.add(m, data);
}
}
});
return this;
},
/* Function for deselect body contents */
disableSelection : function(target) {
if(typeof target.onselectstart != "undefined")//IE
target.onselectstart = function() {
return false;
}
else if(typeof target.style.MozUserSelect != "undefined")//Firefox
target.style.MozUserSelect = "none"
else//All other
target.onmousedown = function() {
return false
}
target.style.cursor = "default"
}
});
var blockView = Backbone.View.extend({
initialize : function(formalObj){
console.log("block view");
$("#canvasdiv").mousemove(this, this.mousemove).mouseup(this, this.mouseup);
this.model.set({id : formalObj.data.id});
console.log(JSON.stringify(collection));
var nodeObj = this.block(formalObj.data);
},
block : function(data){
var Obj = new draw2d.node();
var self = this;
Obj.onDoubleClick = function(){
self.informationBlock(Obj.getnodeName());
};
Obj.setTitle(collection.get(data.id).get("id")+" "+ (uniqueid++));
Obj.setFooter("#" + (++blockCounter));
WorkSpace.addFigure(Obj, data.evt.pageX - 205, data.evt.pageY);
});
return{
view : view,
blockView : blockView
}
}();