[英]Draggabilly.js events in the Backbone.js view
I am using Draggabilly.js inside a Backbone view as follows: 我在Backbone视图中使用Draggabilly.js,如下所示:
var appView = Backbone.View.extend({
initialize: function(){
this.render();
},
render: function(){
var draggie = new Draggabilly(this.el);
draggie.on('dragEnd', this.updateModel); //This works by I can access the this.model
},
events: {
'dragEnd':'updateModel' //This doesn't work
},
updateModel: function(instance, event, pointer){
//Here I want to update my model bassed on the pointer's x and y
//However I can't access this.model
}
)};
Draggabilly provides and event 'dragEnd'
for when the draginng is over. Draginng结束时,Draggabilly提供事件
'dragEnd'
。 However I can integrate this in my Backbone view as an event. 但是,我可以将其作为事件集成到我的Backbone视图中。
Can you please advice? 你能请教吗?
In order to access to the View
context you can do: 为了访问
View
上下文,您可以执行以下操作:
draggie.on('dragEnd', _.bind( this.updateModel, this ));
But, if you want to remove the listener of dragEnd
later it might be useful to use bindAll
in your initialize code: 但是,如果以后要删除
dragEnd
的侦听器,则在初始化代码中使用bindAll
可能会很有用:
initialize: function() {
_.bindAll(this, 'updateModel');
}
Check the Backbone documentation for further info . 查看Backbone文档以获取更多信息 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.