如何在Meteor Spacebars模板中重复一次N次?

rad*_*von 5 meteor spacebars meteor-blaze

我在Spacebars模板中有这段代码:

1.
<select class="form-group">
  {{#each choices}}
    <option>{{this}}</option> 
  {{/each}}
</select>
Run Code Online (Sandbox Code Playgroud)

我想重复这个N次,每次增加数量,如下:

1.
<select class="form-group">
  {{#each choices}}
    <option>{{this}}</option> 
  {{/each}}
</select>
2.
<select class="form-group">
  {{#each choices}}
    <option>{{this}}</option> 
  {{/each}}
</select>
3.
<select class="form-group">
  {{#each choices}}
    <option>{{this}}</option> 
  {{/each}}
</select>
Run Code Online (Sandbox Code Playgroud)

我希望能够将N传递给自定义模板标签来处理这个问题(例如{{choices 3}}).这样做有什么好干的方法?我有一个模糊的概念,我可以写一个模板助手,但我不知道从哪里开始.

hee*_*eya 7

工作示例: http ://meteorpad.com/pad/THAQfpfrru5MgAGnS/Copy%20of%20Leaderboard

您可以传递计数并返回任意对象的数组.不是最优雅......但它确实有效!

HTML

<body>
  {{>content}}
</body>

<template name="content">
    {{#each loopCount 5}}
      <select class="form-group">
        {{#each choices}}
          <option>{{this}}</option> 
        {{/each}}
      </select>
    {{/each}}
</template>
Run Code Online (Sandbox Code Playgroud)

JS

Template.content.helpers({

  choices: function(){
    return ['choice1','choice2','choice3']
  },

  loopCount: function(count){
    var countArr = [];
    for (var i=0; i<count; i++){
      countArr.push({});
    }
    return countArr;
  }

});
Run Code Online (Sandbox Code Playgroud)