Meteor Template不会在每个语句中输出数据
Meteor Template does not output data in each statement
我有以下三个文件:
- abc.js
- abc.html
- router.js
如果HTML被模板包围,则HTML中的每个语句都不输出数据。删除模板是在输出数据。
//file name : abc.js
if (Meteor.isClient) {
// This code only runs on the client
Template.body.helpers({
tasks: [
{ text: "This is task 1" },
{ text: "This is task 2" },
{ text: "This is task 3" }
]
});
}
//file name router.js
Router.map(function () {
this.route('mylist',{
path:'/list',
});
});
//file name: abc.html
<template name="mylist">
<body>
<div class="container">
<header>
<h1>Todo List</h1>
</header>
<ul>
{{#each tasks}}
{{> task}}
{{/each}}
</ul>
</div>
</body>
</template>
<template name="task">
<li>{{text}}</li>
</template>
为什么模板不使用#each
语句输出数据?
您正在使用Template.body.helpers
而不是mylist
助手。
试着这样修改你的代码:
if (Meteor.isClient) {
// This code only runs on the client
Template.mylist.helpers({
tasks: [
{ text: "This is task 1" },
{ text: "This is task 2" },
{ text: "This is task 3" }
]
});
}
您还应该从mylist
模板中删除<body>
标签,并将模板mylist
包含在html body
:
<body>
{{>mylist}}
</body>
<template name="mylist">
<div class="container">
<header>
<h1>Todo List</h1>
</header>
<ul>
{{#each tasks}}
{{> task}}
{{/each}}
</ul>
</div>
</template>
<template name="task">
<li>{{text}}</li>
</template>
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 如何在ReactJS JSX中执行嵌套的if-else语句
- 在JavaScript中输出转义字符
- 如何在jQuery中将函数的输出分配给变量
- Javascript OOP-为什么这两个几乎完全相同的语句给出不同的输出
- for语句循环小写输出
- 在 HTML 中循环写入(输出)语句
- JavaScript - 为什么在使用语句之前声明的变量时与 if/else 语句的输出不同
- 与 for 的结果混淆..在语句 JS 输出中
- 使用Switch语句的JavaScript-没有得到预期的输出
- 输出在 JavaScript 中不带语句
- Javascript if/else语句不返回任何输出
- 通过if else语句显示特定的输出
- Meteor Template不会在每个语句中输出数据
- “甚至Steven"输出奇数的While语句取代偶数
- 返回错误输出的Javascript条件语句
- 淡出使用if语句输入和输出
- 复杂的if语句运行代码而不考虑条件输出
- 如果..否则如果..语句在 JavaScript 中没有给出任何输出
- Javascript对象未定义关键字在输出语句结束