如何在 Meteor 中处理自定义 jQuery 事件? [英] How to handle custom jQuery events in Meteor?

查看:20
本文介绍了如何在 Meteor 中处理自定义 jQuery 事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Metor 0.3.5 中,当所有事件都是 jQuery 事件时,我可以使用 jQuery UI Draggable 然后处理 drag &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
};

但我刚刚在 Meteor 邮件列表中看到了这个:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆