如何处理Meteor中的自定义jQuery事件? [英] How to handle custom jQuery events in Meteor?
问题描述
在Metor 0.3.5中,当所有事件都是jQuery事件时,我可以使用 jQuery UI Draggable ,然后处理 拖动
& dragstop
事件使用Metor 事件映射:
In Metor 0.3.5, when all events were jQuery events, I was able to use use jQuery UI Draggable and then handle the drag
& dragstop
events using a Metor event map:
Template.game.events['dragstop .card'] = function (e) {
//stuff
};
但我只是在流星邮件列表中阅读:
But I just read this in the Meteor mailing list:
在0.3.6中,事件地图不再依赖于jQuery
In 0.3.6, event maps no longer depend on jQuery
,上述技术不再似乎工作–我的 dragstop
处理程序现在都没有被调用。
And sure enough, the above technique no longer seems to work – my dragstop
handler isn't called at all now.
我非常感谢任何关于如何在0.3.6中实现相同的效果。
I'd greatly appreciate any advice as to how to achieve the same effect in 0.3.6.
推荐答案
自定义jQuery事件可以用简单的旧的jQuery绑定,绕过事件地图总共:
Custom jQuery events can be bound with plain old jQuery, bypassing event maps altogether:
$(function () {
$('body').on('dragstop', '.card', function (e) {
//stuff
});
});
请记住使用jQuery的 on
功能来绑定处理程序,因为模板元素始终不包括在DOM中。
Remember to use jQuery's on
function to bind the handlers, since template elements are not necessarily included in the DOM at all times.
这篇关于如何处理Meteor中的自定义jQuery事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!