迭代流星模板中的对象数组

时间:2014-05-27 02:29:27

标签: meteor spacebars

[
  {name:"foo",last:"bar",age:100},
  {name:"baz",last:"foobar",age:200},
]

有没有办法如何使用{{#each}}帮助器将其迭代到流星模板

<template name='boo'>
  {{#each objectInArray}}
    <span> {{namehere}} </span>
  {{/each}}
</template>

1 个答案:

答案 0 :(得分:1)

你可以这样做:

<template name="boo">
  {{#each objectInArray}}
    <span> {{foo}} </span>
    <span> {{last}} </span>
    <span> {{age}} </span>
  {{/each}}
</template>
Template.boo.objectInArray = function() {
  return [
    {name:"foo",last:"bar",age:100},
    {name:"baz",last:"foobar",age:200},
  ]
}