admin管理员组文章数量:1323336
Wondering if anyone has e up with a better way for handling a click outside a div while using Ember? I know of the jQuery way with a global click handler that you must specify each action to take for certain instances, but am hoping someone has e up with a way to declare this inside an Ember view. As well, I tried the ol' give a div a tab index and use the on blur, but Ember actions don't seem to allow this.
Wondering if anyone has e up with a better way for handling a click outside a div while using Ember? I know of the jQuery way with a global click handler that you must specify each action to take for certain instances, but am hoping someone has e up with a way to declare this inside an Ember view. As well, I tried the ol' give a div a tab index and use the on blur, but Ember actions don't seem to allow this.
Share asked Apr 24, 2013 at 22:56 chris brownchris brown 1611 silver badge8 bronze badges 2-
1
I don't understand what the issue is. You can delegate the event based on a regexp expression, this doesn't require anything crazy. Even taking a look at the Ember.js documentation states that leveraging jQuery's
.on()
method is the approach they use to solving delegation issues along large subsets of elements, nested or not. – Ohgodwhy Commented Apr 24, 2013 at 23:08 -
1
You can use the
didInsertElement
event to start up a plug-in and things like that. And you should usewillDestroyElement
to remove bindings. Alternatively you can useView#on
. – MilkyWayJoe Commented Apr 25, 2013 at 0:15
2 Answers
Reset to default 7Thanks for the input. I went back and read the documentation on jQuerys .on
again. I was not aware that you could namespace the event. So I took both of the ments and bined them with something like this.
didInsertElement: function() {
Ember.run.next(this, 'attachClickHandler');
},
attachClickHandler: function (){
var temp = this;
$(window).on("click." + temp.elementId, function (e){
//...event here
});
},
detachClickHandler: function (){
$(window).off("click." + this.elementId);
},
This allows for the event to be specific for each view instance, which is what I was wanting. Thanks guys!
you may find ClickElsewhereMixin useful
just include the mixin on any ponent and implement onClickElsewhere()
本文标签: javascriptEmberHandling clicks outside of viewStack Overflow
版权声明:本文标题:javascript - Ember - Handling clicks outside of view - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742138016a2422456.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论