流星收集发现后,全球的关键

Meteor - collection find after global keydown?

本文关键字:发现 流星      更新时间:2023-09-26

我已经搜索了所有和流星似乎不能够在同一时间做这两件事。

我想要的很简单:当任何按钮被按下(全局),一个collection.find(…)被调用。这在模板中是不可行的。事件,因为流星不支持全局keydown的,我不能做它在模板。渲染是因为,出于某种原因,集合。查找总是不返回任何内容。

任何想法?

下面的工作,但需要在页面中的元素有焦点,我想这是你的情况下的问题。

UI.body.events({
    'keydown': function(event, template){
        console.log('A key is down!')
    } 
})

我猜你必须没有流星。下面的代码应该可以在现代浏览器中工作:

function keydownListener(event){
    console.log('A key is down!')
}
Template.templateName.created = function(){
    document.body.addEventListener('keydown', keydownListener)
}
Template.templateName.destroyed = function(){
    document.body.removeEventListener('keydown', keydownListener)
}