带路由器的流星 - 模板事件未触发

时间:2021-10-15 18:06:33

I had a lot of code that was working, but needed a way to be able to switch "pages" with Meteor, the most commonly suggested solution being the use of iron-router. Following their documentation, I put each page into a Template, as in the following:

我有很多代码正在运行,但需要一种能够用Meteor切换“页面”的方法,最常见的解决方案是使用铁路由器。在他们的文档之后,我将每个页面放入一个模板中,如下所示:

<template name="home">
    <input type="date" id="start-date" style="width:1px;height:1px;padding:0;">
    <!-- More Random Code --> 
</template>

which is rendering properly, after I used:

在使用之后,它正确渲染:

Router.route('/', function () {
  // render the Home template with a custom data context
  this.render('home', {data: {}});
}); 

Before I was using:

在我使用之前:

Template.body.events({

}); 

which I changed to:

我改为:

Template.home.events({

}); 

However, the code loaded into this no longer works. One function being called inside this is:

但是,加载到此的代码不再有效。在其中调用的一个函数是:

    "blur #start-date": function (event) {
        if( Meteor.user() && !StartDate.find({email:Meteor.user().emails[0].address}).fetch().length){
            var date = event.target.value;
            StartDate.insert({
                date: date,
                createdAt: new Date(), // current time
                user: Meteor.user()._id,
                email: Meteor.user().emails[0].address
            });
        }else{

        }
    }

1 个解决方案

#1


0  

It worked when you were using Template.body because it was operating within the body area of the file. In the snippet of the "home" template you provided, there is no body and even though it is recognized as a template, there is nothing to actually render in there. add head, body tags and also an area for things to actually be rendered. See also: Meteor nested views and yields

它在您使用Template.body时有效,因为它在文件的正文区域内运行。在您提供的“主页”模板的片段中,没有正文,即使它被识别为模板,也没有什么可以在那里实际渲染。添加头部,身体标签以及实际渲染事物的区域。另请参见:Meteor嵌套视图和产量

#1


0  

It worked when you were using Template.body because it was operating within the body area of the file. In the snippet of the "home" template you provided, there is no body and even though it is recognized as a template, there is nothing to actually render in there. add head, body tags and also an area for things to actually be rendered. See also: Meteor nested views and yields

它在您使用Template.body时有效,因为它在文件的正文区域内运行。在您提供的“主页”模板的片段中,没有正文,即使它被识别为模板,也没有什么可以在那里实际渲染。添加头部,身体标签以及实际渲染事物的区域。另请参见:Meteor嵌套视图和产量