我处于基础水平,有一个问题,那就是,在 meteor 中,如果我在 Javascript 文件中使用模板名称而不是正文,那么它不起作用。
这是我的 html 代码:
<head>
<title>simple</title>
</head>
<body>
<ul>
{{#each player}}
<li> {{text}}</li>
{{/each}}
</ul>
</body>
<template name="shahin">
{{player}}
</template>
JavaScript 代码:
Template.shahin.helpers({
player: [
{ text: "This is paragraph 1..." },
{ text: "This is paragraph 2..." },
{ text: "This is paragraph 3..." },
{ text: "This is paragraph 4..." },
{ text: "This is paragraph 5..." }
]
});
现在,如果我运行此代码,它不会显示任何内容。但我用这个更改为我的模板名称
Template.body.helpers
那么代码就可以工作了。有人可以解释一下为什么会这样吗?让我知道为什么这不起作用:
Template.shahin.helpers
最佳答案
它不起作用,因为您没有在 body 的任何地方调用模板。
试试这个:
<head>
<title>simple</title>
</head>
<body>
{{> shahin}} <!-- this is where the contents of template="shahin" will render. If you don't call this, "shahin" will never get displayed -->
</body>
<template name="shahin">
<ul>
{{#each player}}
<li> {{text}}</li>
{{/each}}
</ul>
</template>
关于javascript - 在 meteor 中,如果我使用模板名称而不是正文,那么它不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47254637/