Meteor 如何基于集合';s码?

Meteor 如何基于集合';s码?,meteor,handlebars.js,Meteor,Handlebars.js,我想这样做: <template name="list"> <ul> {{#if items}} {{#each items}} <li>{{itemContents}}</li> {{/each}} {{else}} <li class="placeholder">There are no items in this list.</li> {{/if}}

我想这样做:

<template name="list">
  <ul>
  {{#if items}}
      {{#each items}}
        <li>{{itemContents}}</li>
      {{/each}}
  {{else}}
    <li class="placeholder">There are no items in this list.</li>
  {{/if}}
  <ul>
</template>
但是,上面的代码不起作用,因为即使没有项目,条件也会进行正向计算(这有点令人惊讶,因为Handlebar的计算结果是错误的)。我试着把条件改成

{{#if items.count}}
但是我得到了一个神秘的错误

Unknown helper 'items'

那么,有没有办法在meteor车把模板中写出这样的条件呢?

过去几周我一直在评估车把,我遇到了类似的问题。对我有效的方法是读取length属性并添加else标记

    {{#if competitions.length}}
        <div class="game-score span-4"> 
        ...code goes here...    
        </div>
   {{else}}
        {{> allGameNotes}}
   {{/if}
{{{#if competities.length}
…代码在这里。。。
{{else}
{{>allGameNotes}
{{/if}

我可以通过使用
更改评估上下文,使我的模板正常工作:

<template name="list">
  <ul>
  {{#with items}}
    {{#if count}}
        {{#each this}}
          <li>{{itemContents}}</li>
        {{/each}}
    {{else}}
      <li class="placeholder">There are no items in this list.</li>
    {{/if}}
  {{/with}}
  <ul>
</template>

    {{#带项目} {{#如果计数} {{{#每个这个}
  • {{itemContents}}
  • {{/每个}} {{else}
  • 此列表中没有项目
  • {{/if} {{/与}}

注意修改后的表达式
{{if count}
{{each this}

这是正确的方法:

<template name="list">
  <ul>
  {{#each items}}
    <li>{{itemContents}}</li>
  {{else}}
    <li class="placeholder">There are no items in this list.</li>
  {{/each}}
  <ul>
</template>

    {{{#每项}
  • {{itemContents}}
  • {{else}
  • 此列表中没有项目
  • {{/每个}}
有关更多信息,请参阅


(Meteor使用的是受把手启发的。因此语法几乎相同。)

这对我不起作用。我得到的错误与我尝试使用
count
时的错误相同。在这种情况下,这将是
未知助手的“竞争”。
如果OP声明如下项:
Template.list.helpers,那么他的代码不应该起作用({items:function(){return items.find()};
我不这么认为。他遇到的问题是
[]!==false
<template name="list">
  <ul>
  {{#each items}}
    <li>{{itemContents}}</li>
  {{else}}
    <li class="placeholder">There are no items in this list.</li>
  {{/each}}
  <ul>
</template>