有没有更好的方法来根据与Meteor.js反应的输入字段更新html?

Nea*_*int 4 jquery reactive-programming handlebars.js angularjs meteor

我看到本教程用Angular.js编写了一个演示应用程序.它是Todo演示(http://angularjs.org),他只需在文本框中键入内容,然后轻松地在页面上反映出来.

我想在Meteor中重新创建这个功能,但效果不佳.首先,由于某种原因,它不会更新最后一个字母.使用Angular.js执行此演示视频也更容易,效果更好,有没有更好的方法在Meteor中执行此操作?

另外,如果有办法访问DOM而不是辅助函数?在事件函数中,我可以使用't'变量来访问DOM,但是在helpers函数中我不知道如何,例如我是否想从helper函数中的div中获取文本.我不知道怎么做.

这是我的Meteor代码,这是一个现场演示:http://todotestapp.meteor.com

提前致谢

HTML

<head>
  <title>Todo</title>
</head>

<body>
  {{> hello}}
</body>

<template name="hello">
  <input id="personName" type="text">
  <h1>Hello {{personName}}!</h1>

</template>
Run Code Online (Sandbox Code Playgroud)

流星Javascript

if (Meteor.isClient) {
Template.hello.helpers({
    personName: function () {
        return Session.get("personName");
    }
});

Template.hello.events({
    'keypress #personName': function (e, t) {
        Session.set("personName", t.find("#personName").value);
    }
});

}
Run Code Online (Sandbox Code Playgroud)

sai*_*unt 5

您应该使用"输入"事件.不需要使用jQuery,模板实例.find方法很好.

Template.hello.events({
    'input #personName': function (e, t) {
        Session.set("personName", t.find("#personName").value);
    }
});
Run Code Online (Sandbox Code Playgroud)

这按预期工作.