我查遍了,Meteor似乎不能同时做这两件事。
我想要的很简单:当按下任何按钮(全局)时,将调用 collection.find(...) 。它在 Template.events 中不可行,因为 Meteor 不支持全局 keydown,而且我无法在 Template.rendered 中执行此操作,因为出于某种原因,collection.find 始终不返回任何内容。
有什么想法吗?
最佳答案
以下方法有效,但需要页面中的元素具有焦点,我猜这就是您的情况的问题。
UI.body.events({
'keydown': function(event, template){
console.log('A key is down!')
}
})
我想你必须在没有 Meteor 的情况下做到这一点。以下内容应该适用于现代浏览器:
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)
}
关于javascript - Meteor - 全局 keydown 后找到集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24517449/