【问题标题】:What do i need to add to render each articles in my meteor Articles collection?我需要添加什么来渲染我的流星文章集合中的每篇文章?
【发布时间】:2014-04-27 07:10:11
【问题描述】:

我想渲染我的流星文章集合中的每篇文章。 (文件位于myProject/collections/collections.js,因此它应该可用于客户端和服务器)

collections.js 中的代码:

Articles = new Meteor.Collection('articles');

我已经安装了 autopublish 包,并且我通过 Chrome 控制台在文章集合中插入了一个对象,并通过控制台验证了插入:Articles.findOne()

Articles.insert({name: 'HTML5', description: 'HTML5 for beginners', src: 'https://www.youtube.com/watch?v=9gTw2EDkaDQ'})

到目前为止我得到的是:

<head>
  <title>Articles</title>
</head>

<body>
  {{> main}}
</body>

我的主要模板是不显示文章的模板。

<template name="main">
  <div class="container-fluid">
    {{#each articles}}
      {{> article}}
    {{/each}}
  </div>
</template>

我的文章模板应该为我的文章集合中的每个对象呈现,如下所示:

<template name="article">
  <div class="item well span4">
    <iframe height="{{height}}" src="{{src}}"></iframe>
    <hr>
    <h4 class="muted">{{name}}</h4>
    <p>{{description}}</p>  
   </div>
</template>

我需要添加什么来呈现这篇文章?如果我要删除自动发布包,我需要做什么来呈现文章?

【问题讨论】:

    标签: collections meteor handlebars.js meteorite


    【解决方案1】:

    我需要添加什么来呈现这篇文章?

    你需要告诉你的main模板如何计算字段articles。您只需在模板上调用helpers 方法即可。

    如果我要移除 自动发布包?

    您需要创建一个publish,以便客户端可以通过subscribing 获取集合中的文档。

    【讨论】:

    • 我将如何设置该助手方法? Template.main.articles = function () { return Articles.find(); }; - 这也不会给我任何回报。我发现这方面的文档不太清楚。希望有更多的帮助@Peppe L-G
    • @getJETsetTER 您的助手对我来说似乎是正确的。然而,在我原来的帖子中,我写{{articles}} 可能会让你感到困惑。在您的模板中,您当然应该使用{{#each articles}},就像您一样。如果这不是问题,那我不知道出了什么问题。
    • 我重新启动了流星,现在它正在显示。谢谢佩佩。希望我能在瓦拉校园见到你! ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-23
    • 2021-08-04
    • 2018-01-29
    • 2018-01-31
    • 1970-01-01
    相关资源
    最近更新 更多