【问题标题】:Getting started w/ Meteor - Display Collection开始使用 Meteor - 显示集合
【发布时间】:2016-06-21 18:29:42
【问题描述】:

我是 Javascript 和 Meteor 的新手 - 我确信我犯了一个非常基本的错误。

我正在尝试了解如何显示集合的内容。

这是基于 Meteor 网站上的教程 - 我已将“Tasks”替换为“sw”,这也是我收藏的名称

 Template.HomePrivate.helpers({

});

sw = new Mongo.Collection("sw");

if (Meteor.isClient) {
  // This code only runs on the client
  Template.body.helpers({
    text: function () {
      return sw.find({});
    }
  });
}

HTML:

<template name="HomePrivate">
    <div class="page-container container" id="content">
        <div class="row" id="title_row">
            <div class="col-md-12">
                <h2 id="page_title" class="pull-left">
                    Welcome {{userFullName}}!
                </h2>
                <div id="page_menu" class="pull-right">
                </div>
            </div>
        </div>
    </div>
  <div class="container">
    <header>
      <h1>Sight Words</h1>
    </header>
 <p>begin list</p>
    <ul>
      {{#each sw}}
        {{> sw}}
      {{/each}}
    </ul>
    <p>end list</p>
  </div>
</template>

<template name="sw">
  <li>{{text}}</li>
</template>

【问题讨论】:

    标签: javascript meteor meteor-helper


    【解决方案1】:

    您的 #each 循环没有显示任何内容,因为 sw 没有被定义为帮助程序:

    {{#each sw}}
      {{> sw}}
    {{/each}}
    

    在使用#each 循环时,Blaze 会查找帮助程序名称 - 我认为这就是您的困惑所在。在这种情况下,您想使用上面定义的帮助器,text

    {{#each text}}
      {{> sw}}
    {{/each}}
    

    sw 尚未被定义为助手,因此 Blaze 无法识别它。

    现在,{{&gt; sw}} 是有效的语法,因为它被定义为 模板(这就是 > 符号的用途)。假设您的 sw 集合有一个字段 text,您的 #each 循环现在应该正确显示。

    【讨论】:

      猜你喜欢
      • 2016-03-23
      • 1970-01-01
      • 2016-07-08
      • 2016-12-24
      • 2020-08-31
      • 2015-04-03
      • 2015-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多