简体   繁体   English

模板的meteorjs keyup事件

[英]meteorjs keyup event for template

I am following a Meteor.js tutorial , but I am stuck at this one point. 我正在关注Meteor.js教程 ,但是我停留在这一点上。

'keyup [name=todoItem]': function(event){
  console.log("You just tapped a key on your keyboard.");
}

is not working 不管用

Here is my code: 这是我的代码:

Template.todoItem.events({
  'click .delete-todo': function(event) {
    event.preventDefault();
    var documentId = this._id;
    Todos.remove({_id: documentId});
  },
  'keyup [name=todoItem]': function(event) {
    console.log("just tapped key on keyboard");
  }
});

Thanks in advance! 提前致谢!

The above code seems correct and I'm not sure what the real problem is. 上面的代码似乎正确,我不确定真正的问题是什么。 Try the following: 请尝试以下操作:

  1. Give an id=todoItem to the element, and use #todoItem instead of [name=todoItem] to see if that works. 给该元素指定一个id = todoItem,并使用#todoItem而不是[name = todoItem]来查看是否可行。

  2. Check if you have rightly named the template to "todoItem" 检查您是否正确将模板命名为“ todoItem”

  3. Try on another browser. 尝试使用其他浏览器。

If none of the above works, the problem is probably in some other part of your code. 如果以上方法均无效,则问题可能出在代码的其他部分。

Yes, the above code is correct. 是的,上面的代码是正确的。 Please read carefully: 请仔细阅读:

All of these event types react to when keys are pressed on a keyboard .. 当按下键盘上的键时,所有这些事件类型都会做出反应。

You can try by press any keyboard and see console log; 您可以按任意键盘尝试查看控制台日志。 you aren't seeing anything currently because you are not pressing on the keyboard. 您目前没有看到任何东西,因为您没有按键盘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM