Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor.js-通过对象数组循环_Javascript_Meteor_Meteor Blaze_Meteor Helper - Fatal编程技术网

Javascript Meteor.js-通过对象数组循环

Javascript Meteor.js-通过对象数组循环,javascript,meteor,meteor-blaze,meteor-helper,Javascript,Meteor,Meteor Blaze,Meteor Helper,我有一个小的列表构建应用程序,相当于一个待办事项列表 我有一个叫“列表”的收藏 Lists = new Meteor.Collection('lists') 我有一个表格可以提交给这个集合,而且效果很好 我的模板在这里: <template name="list"> {{#with list}} <ul> {{#each links}} <li>PLEASE WORK! >>>> {{title}}<

我有一个小的列表构建应用程序,相当于一个待办事项列表

我有一个叫“列表”的收藏

Lists = new Meteor.Collection('lists')
我有一个表格可以提交给这个集合,而且效果很好

我的模板在这里:

<template name="list">
  {{#with list}}
    <ul>
    {{#each links}}
    <li>PLEASE WORK! >>>> {{title}}</li>
    {{/each}}
    </ul>
  {{/with}}
</template>
我知道我订阅了数据库,因为当我订阅时:

Lists.find({_id : currentListId}).fetch()
它返回一个如下所示的对象

_id: "mrkpjGW2"
createdAt: 1447401698770
items: Array[3]
__proto__: Object
和内部项目

items: Array[3]
    0: Object
        createdAt: 1447402263732
        owner: "3oyKZKhdPZyDkWnZm"
        title: "google.com"
        __proto__: Objec

因此,我想循环查看项目,并获取标题。

我没有看到
链接
帮助程序。您在链接上迭代,但它是否已定义?另外,在您的示例中,您有不同的模板名称—HTML代码中的
list
,JS中的
linkList

您有{{{each links}},但什么是链接?我看不出它在任何地方有定义

当你回来的时候

list: function () {
      currentListId = Session.get('currentListId')
      return Lists.find({
        _id : currentListId
      });
    }
你可以直接在上面迭代,而不是在顶部{{{#with list}},把它取出来,只使用下面的{{#each list}

<template name="list">
    <ul>
    {{#each list}}
    <li>PLEASE WORK! >>>> {{title}}</li>
    {{/each}}
    </ul>
</template>

    {{{#每个列表}
  • 请工作!>>>>{{title}}
  • {{/每个}}

您已经使用helper为blaze提供了列表,这就足够了,不需要为标题创建helper。您可以直接从blaze迭代项目并获取标题。
据我所知,您希望迭代项目数组,并从每个项目获取标题。所以,在javascript中

Template.list.helpers({
    list: function () {
        currentListId = Session.get('currentListId')
        return Lists.find({
        _id : currentListId
      }).fetch();
    }
  })
在html中

<template name="list">
    <ul>
        {{#each list}}
            <li>PLEASE WORK! >>>> {{title}}</li>
        {{/each}}
    </ul>
</template>

    {{{#每个列表}
  • 请工作!>>>>{{title}}
  • {{/每个}}
为什么不
{{{#每个项目}}
<template name="list">
    <ul>
        {{#each list}}
            <li>PLEASE WORK! >>>> {{title}}</li>
        {{/each}}
    </ul>
</template>