Javascript unbind.js下划线
我很想解开这个:Javascript unbind.js下划线,javascript,raphael,backbone.js,underscore.js,Javascript,Raphael,Backbone.js,Underscore.js,我很想解开这个: $("body").mousemove(_.bind(this.mousemove, this)); 由于backbone.js和raphael.js之间的复杂混合,我需要通过underline.js进行绑定: var NodeView = Backbone.View.extend({ dx: 0, dy: 0, click: function(event){ alert('hello')
$("body").mousemove(_.bind(this.mousemove, this));
由于backbone.js和raphael.js之间的复杂混合,我需要通过underline.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;
}
});
有什么建议吗?谢谢@Pointy(谢谢:D):
解决方案很简单,如:$(“body”).unbind(“mousemove”)
请参阅第一篇文章中的注释。这也是jQuery代码混合在一起的原因吗?此外,下划线“bind”在这里不太可能成为问题。看起来您需要做的是取消绑定事件处理程序,这与下划线“bind”的用途(直接)无关。它所做的就是为函数提供一个预先绑定的
这个值。问题是我有一个主干视图和一个Raphäel对象,我需要更新附加到视图的主干模型。如果我将事件直接绑定到Raphäel对象…$(“body”)。unbind(“mousemove”);工作。我可以给你一些stackoverflow积分吗?@ichbinadrian如果你愿意,你可以回答你自己的问题,然后我可以投票给你:-)