我试图在流星中吐出我正在保留的数组的列表;不显示

I am trying to spit out a list in Meteor of an array I am keeping; not showing

本文关键字:数组 列表 显示 保留 流星      更新时间:2023-09-26

我的appname.js文件中有一个数组,如下所示:

if (Meteor.isClient) {
  Template.body.helpers({
    tasks: [
      { text: "This is task 1" },
      { text: "This is task 2" },
      { text: "This is task 3" }
    ]
  });
}

我在客户端文件夹中有一个文件夹"视图",我在其中保存了一个"服务.html"文件。 在该文件中,我有:

<template name="services">
              <ul>
                {{#each tasks}}
                  {{> task}}
                {{/each}}
              </ul>
</template>
<template name="task">
<li>{{text}}</li>
<template>

但是,任务不会显示在视图中。 这是怎么回事?

您使用了错误的模板。它应该是Template.services.helper而不是Template.body.helper