I want add the contents of a textarea (or a textfield) to a reactive variable and bind it to a view, similar to AngularJS double binding.
The problem to listen to keydown
is that the last character will not be included. If I use keyup
there will be a delay. Is there a way to listen to value change in a text field and immediately after it changes set the reactive variable?
Template.body.events({
"keydown #textarea":function(){
input.set( $('#textarea').val());
}
});
答案 0 :(得分:1)
You can use the HTML5 input
event which is probably better suited for what you need.
Template.body.events({
"input #textarea":function(){
input.set( $('#textarea').val());
}
});