Meteor Template.myTemplate.helpers 不渲染输出
Meteor Template.myTemplate.helpers not rendering output
我是 meteor 的新手,我想知道为什么当我开始将这些文件放入我的 /client/template 目录时,myTemplate.helper 没有呈现其预期的输出。这些是以下文件:
/clinent/template/body.html:
<body>
<div class="row">
<div class="col-xs-12">
<div class="list-group">
{{#each projects}}
{{> projectList}}
{{/each}}
</div>
</div>
</div>
</body>
/client/template/body.js:
Project = new Mongo.Collection("project");
if (Meteor.isClient) {
Template.body.helpers({
projects: function(){
var projects = Project.find({});
return projects;
}
});
};
/client/template/templates.html:
<template name="projectList">
<a href="#" id="{{id}}" class="list-group-item {{#if active}} active {{/if}}">
{{name}}
<i class="glyphicon glyphicon-trash pull-right del"></i>
</a>
</template>
然而,当我将 body.html 和 body.js 放在 /
根目录时,它会正确呈现输出。
我想我知道问题出在哪里了。
Project = new Mongo.Collection("project");
应该对客户端和服务器都可用,当您将 body.js 移动到客户端文件夹时,它会自动 served only to client,它会破坏应用程序。
尝试以下结构:
/client/template/body.js:
Template.body.helpers({
projects: function(){
var projects = Project.find({});
return projects;
}
});
/collections.js
Project = new Mongo.Collection("project");
请注意,在客户端文件夹中创建文件时不需要 if(Meteor.isClient)。
我认为如果你使用
它会起作用
Template.projectList.helpers
而不是
Template.body.helpers
当助手用于模板时,您必须输入模板名称而不是正文。
我是 meteor 的新手,我想知道为什么当我开始将这些文件放入我的 /client/template 目录时,myTemplate.helper 没有呈现其预期的输出。这些是以下文件:
/clinent/template/body.html:
<body>
<div class="row">
<div class="col-xs-12">
<div class="list-group">
{{#each projects}}
{{> projectList}}
{{/each}}
</div>
</div>
</div>
</body>
/client/template/body.js:
Project = new Mongo.Collection("project");
if (Meteor.isClient) {
Template.body.helpers({
projects: function(){
var projects = Project.find({});
return projects;
}
});
};
/client/template/templates.html:
<template name="projectList">
<a href="#" id="{{id}}" class="list-group-item {{#if active}} active {{/if}}">
{{name}}
<i class="glyphicon glyphicon-trash pull-right del"></i>
</a>
</template>
然而,当我将 body.html 和 body.js 放在 /
根目录时,它会正确呈现输出。
我想我知道问题出在哪里了。
Project = new Mongo.Collection("project");
应该对客户端和服务器都可用,当您将 body.js 移动到客户端文件夹时,它会自动 served only to client,它会破坏应用程序。
尝试以下结构:
/client/template/body.js:
Template.body.helpers({
projects: function(){
var projects = Project.find({});
return projects;
}
});
/collections.js
Project = new Mongo.Collection("project");
请注意,在客户端文件夹中创建文件时不需要 if(Meteor.isClient)。
我认为如果你使用
它会起作用Template.projectList.helpers
而不是
Template.body.helpers
当助手用于模板时,您必须输入模板名称而不是正文。