首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ember.js中使用自定义jquery-事件

在ember.js中使用自定义jquery-事件
EN

Stack Overflow用户
提问于 2013-04-18 17:37:24
回答 1查看 1.6K关注 0票数 0

我在我的jQuery应用程序中使用了一个定制的jQuery UI插件,并且希望对一个定制的jQuery事件做出反应,以便更新控制器/模型的值。

我所发现的是:在堆栈溢出中请求的question给出了在视图的didInsertElement-函数中使用jQuery.bind()/[jQuery.on() )的答案。在视图的didInsertElement-方法中使用jQuery.on()会导致事件处理程序中的这个问题被绑定到它发生的Dom元素上。

因此,理想情况下,有一种方法可以让其他jQuery事件像ember带来的那样工作:在Ember.View-实例上调用匹配的方法名。

您知道如何使自定义jQuery事件正常工作吗?是否可以使用Mixin在视图上创建适当的方法,等等?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-19 12:36:58

听起来这是一个Javascript问题,而不是jQuery或Ember问题。理解和操作“这”必然是Javascript中最大的学习曲线之一:

代码语言: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

希望这能帮上忙!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16089647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档