我在我的jQuery应用程序中使用了一个定制的jQuery UI插件,并且希望对一个定制的jQuery事件做出反应,以便更新控制器/模型的值。
我所发现的是:在堆栈溢出中请求的question给出了在视图的didInsertElement-函数中使用jQuery.bind()/[jQuery.on() )的答案。在视图的didInsertElement-方法中使用jQuery.on()会导致事件处理程序中的这个问题被绑定到它发生的Dom元素上。
因此,理想情况下,有一种方法可以让其他jQuery事件像ember带来的那样工作:在Ember.View-实例上调用匹配的方法名。
您知道如何使自定义jQuery事件正常工作吗?是否可以使用Mixin在视图上创建适当的方法,等等?
发布于 2013-04-19 12:36:58
听起来这是一个Javascript问题,而不是jQuery或Ember问题。理解和操作“这”必然是Javascript中最大的学习曲线之一:
///...in the view
didInsertElement : function(){
var view = this;
this.$().zoomablebg(); //this is the name of the custom jQ UI-Plugin
// the view variable now holds a reference to the ember view
// and creates a closure so that you can refer to it in the event handler
this.$().on("zoomablebgstopdrag", function(e){ view.zoomablebgstopdrag(e) });
},
zoomablebgstopdrag: function(b){
console.log(this); //this refers to the view now.
},
//more view code希望这能帮上忙!
https://stackoverflow.com/questions/16089647
复制相似问题