1
我很想解除绑定此:underscore.js取消绑定
$("body").mousemove(_.bind(this.mousemove, this));
由于Backbone.js的和raphael.js之间的复杂的混合体,我需要做通过underscore.js绑定:
var NodeView = Backbone.View.extend({
dx: 0,
dy: 0,
click: function(event){
alert('hello')
},
mousedown: function(event){
this.dx = event.pageX - this.el.attr('x');
this.dy = event.pageY - this.el.attr('y');
this.el.attr({fill: "#0099FF"});
$("body").mousemove(_.bind(this.mousemove, this));
},
mousemove: function(event){
this.el.attr({ x: event.pageX - this.dx,
y: event.pageY - this.dy});
},
mouseup: function(event){
this.el.attr({fill: "#EEEEEE"});
$("body").mousemove(_.bind(this.mousenotmove, this));
},
render: function(){
this.el = canvas.rect(this.model.get('xPos'), this.model.get('yPos'), 50, 50).attr({
fill: "#EEEEEE",
stroke: "none",
cursor: "move"
});
$(this.el.node).mousedown(_.bind(this.mousedown, this));
$(this.el.node).mouseup(_.bind(this.mouseup, this));
return this;
}
});
有什么建议吗?
那里面还混合了jQuery代码吗? – Pointy 2011-04-08 12:59:14
此外,Underscore“绑定”在这里成为一个问题的可能性极小。它看起来像你需要做的是解除绑定事件处理程序,它没有(直接)与Underscore“绑定”被用于什么。所有它(“_.bind()”)提供的函数都带有一个预先绑定的this值。 – Pointy 2011-04-08 13:03:22
是的,还有jQuery混合在一起。问题是我有一个Backbone视图和一个Raphäel对象,我需要更新附加到视图的Backbone模型。我不能这样做,如果我将事件直接绑定到Raphäel对象... – thgie 2011-04-08 13:18:53