【问题标题】:meteor templates object with array带有数组的流星模板对象
【发布时间】:2018-01-18 18:41:02
【问题描述】:

我是流星模板的新手,并尝试使用 emails 数组呈现来自下一个用户对象的电子邮件:

{
  "_id" : "8ngggLthJ6NRKJRfG",
  "emails" : [
    {
        "address" : "nazar@mail.com",
        "verified" : false
    }
  ]
}

模板助手:

Template.user.helpers({
  users() {
    return Meteor.users.find({}, { sort: { createdAt: -1 } }).fetch();
  },
});

模板:

<template name="chats">
  <ul>
   {{#each users}}
     {{> user}}
   {{/each}}
 </ul>
</template>


<template name="user">
  <li>{{emails[0].address}}</li>
</template>

但我得到错误:“错误:无法调用非函数:[object Object]”

我该如何解决? 提前致谢。

【问题讨论】:

  • 我认为正确的语法是 emails.[0].address 加上一个点,你可以试试吗?
  • 是的,它对我有帮助!谢谢!

标签: templates meteor


【解决方案1】:

emails 是一个数组,所以请使用emails.[0].address

【讨论】:

    猜你喜欢
    • 2014-07-15
    • 2016-03-07
    • 2015-08-25
    • 2012-02-09
    • 2013-01-10
    • 2018-06-01
    • 2018-07-09
    • 2016-10-07
    • 2014-08-04
    相关资源
    最近更新 更多