【问题标题】:duplicate template with meteor用流星复制模板
【发布时间】:2013-05-27 06:59:14
【问题描述】:

我正在努力了解 Meteor 的基础知识。 我创建了一个流星应用程序(使用陨石) 我有启动脚本生成的基础文件

在我的 html 文件中,我有一个模板:

<body>
<h1>test</h1>
  {{#each items}}
    {{> envelop}}
  {{/each}}
</body>

<template name="envelop">
<div class="envelop"><div class="envelop-inner">
    <h1>{{ title }}</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div></div>
</template>

然后在我的 js 文件中我有以下代码:

if (Meteor.isClient) {
  itemsData = [
    {title: 'test1'},
    {title: 'test2'},
    {title: 'test3'}
  ];
  Template.envelop.helpers ({
    items: itemsData
  });
}

我正在尝试让 Meteor 运行并复制部分。 我似乎无法完成这项工作,我不断收到错误。否则页面上不会打印任何内容。

我想我错过了一个基本的东西。

【问题讨论】:

    标签: meteor meteorite


    【解决方案1】:

    您的助手所在的模板将具有items 给出的数据上下文,因此只需将其封装在模板中即可。 items helper 只能被 envelop 看到,但没有更高的权限(例如 body)

    <body>
    <h1>test</h1>
    </body>
    
    <template name="envelop">
      {{#each items}}
        {{>item}}
      {{/each}}
    </template>
    
    <template name="item">
      <div class="envelop"><div class="envelop-inner">
          <h1>{{ title }}</h1>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      </div></div>
    </template>
    

    【讨论】:

    • 魔术,谢谢!没明白。另一个问题是头像图片上的你是哪一个?
    • 哈哈,拍的时候我很害怕,因为它开始看着我
    猜你喜欢
    • 2015-01-10
    • 2015-05-07
    • 2012-06-26
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多