javascript - 在 meteor 中,如果我使用模板名称而不是正文,那么它不起作用

标签 javascript html css meteor meteor-blaze

我处于基础水平,有一个问题,那就是,在 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/

相关文章:

javascript - 使用 async wait 时 axios 不返回数据

javascript - 使用 Array.push() 函数从 Ajax 数据形成 JSON 时出现问题。形成的 JSON 无法使用 jQuery 填充 tbody

javascript - jquery 添加新的选择选项并将数据发送到服务器

html - Bootstrap 的下拉导航不起作用

javascript - 找不到 karma 插件依赖项

javascript - 创建 javascript 小部件时如何管理浏览器 "back"和 "forward"按钮

html - 一个固定宽度的 div 和两个可变的

javascript - 仅在响应式网格中的两个按钮之间留有余量(jquery mobile)

html - 居中页面宽度背景图像正在拉伸(stretch)页面

php - 如何在 WordPress 管理菜单中添加基于用户的链接