現在,對於完全不同的東西。backbone.js&raphäel.js/骨幹視圖<->Raphäel對象
當「dom」對象是 raphäel對象時,如何在骨幹視圖中委派事件。這是否有用?像這樣:
var NodeView = Backbone.View.extend({
events: {
"click": "click"
},
click: function(){
alert('clicked')
},
render: function(){
canvas.rect(this.model.get('xPos'), this.model.get('yPos'), 50, 50).attr({
fill: "#EEEEEE",
stroke: "none",
cursor: "move"
});
return this;
}
});
我需要在raphäel對象改變位置時更新模型。當我直接將事件附加到raphäel對象時,我只能訪問該事件,而不是整個視圖,因此不能訪問模型。
如果我將Element.node分配給el選項,它將無法正常工作。像這樣:this.el = canvas.rect()然後在事件中分配事件:{}。但是,如果我在render()中手動綁定事件,它就會工作:$(this.el).click(_。bind(function(){this.click()},this)); – thgie 2011-04-08 11:53:05