I am using meteor to update a document in the database. However keydown does not seem to be working. here is the code.
Template.leaderboard.events({
'keydown button.inc': function(evt) {
if (evt.which === 39) {
Players.update(Session.get("character"), {$inc: {score: 20}});
}
Players.update(Session.get("character"), {$inc: {score: 20}});
//Players.update(Session.get("character"), {$set: {name: 'images/characters/ninja.png'}});
},
'keydown': function(evt) {
if (evt.which === 37) {
Players.update(Session.get("character"), {$inc: {score: -20}});
//Players.update(Session.get("character"), {$set: {name: 'images/characters/ninjaleft.png'}});
}
Players.update(Session.get("character"), {$inc: {score: -20}});
}
});
Why isn't my keydown working?
I've had success attaching keyboard events to textareas and inputs, like the following:
Template.inputArea.events({
'keydown textarea' : function(e){
console.log(e.which);
}
});
I'm not quite as familiar with attaching keyboard events to other DOM elements. I know for window
events, I've had to use jQuery to attach keydown inputs.
Template.foo.rendered = function(){
$(window).on('keydown', function(e){
console.log(e.which);
});
};
// and on newer versions
Template.foo.onRendered( function() {
$(window).on('keydown', function(e){
console.log(e.which);
});
});
Perhaps you could try something like that...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With