为什么#each 标签不接受数组?

Why does #each tag not accept an array?

我的optionData.js如下:

"options"=
[
{
  "option_text": "Just Me",
  "option_image": "just-me.svg",
  "option_is_selected": false
},
{
  "option_text": "Spouse/Partner",
  "option_image": "spouse-partner.svg",
  "option_is_selected": false
},
{
  "option_text": "Child/Children",
  "option_image": "child-children.svg",
  "option_is_selected": false
},
{
  "option_text": "Grand Children",
  "option_image": "grandchildren.svg",
  "option_is_selected": false
},
{
  "option_text": "Parent(s)",
  "option_image": "parents.svg",
  "option_is_selected": false
},
{
  "option_text": "Pet(s)",
  "option_image": "pets.svg",
  "option_is_selected": false
},
{
  "option_text": "Anyone Else",
  "option_image": "anyone-else.svg",
  "option_is_selected": false
}
]

这是我的 options.js 文件

calc_option_set1: function(){
    var options_set = this.options;
    option_count = options_set.length;
    upperRowObjects = [];

    if(option_count == 2)
    {
        rowBreak = -1;
    }
    else if(option_count % 2 == 0)
    {
        rowBreak = (option_count / 2);
    }
    else
    {
        rowBreak = (option_count + 1) / 2;
    }

    for(i=0; i<rowBreak; i++)
        upperRowObjects = upperRowObjects + options_set[i];
    return upperRowObjects;
},

这是options.html

{{#each option_set1}}
<div class="col-xs-2">
    <center>
        <img src="/images/{{option_image}}" class="img-responsive img-rounded img-option"/>
        <h5>{{option_text}}</h5>
    </center>
</div>
{{/each}}

基本上我想划分选项并将它们呈现在不同的两行中(CSS)。如果我打印 {{calc_option_set1}} 我得到了我想要的一组对象。 但是,如果我尝试像在代码中那样遍历它们,则会收到错误

"Uncaught Error: {{#each}} currently only accepts arrays, cursors or falsey values."

如何遍历方法返回的数组?有什么办法可以将它分配给一个变量然后使用它吗?请帮忙...

数组串联不适用于 + 运算符。请改用 Array.push()。

calc_option_set1: function(){
    var options_set = this.options;
    option_count = options_set.length;
    upperRowObjects = [];

    if(option_count == 2)
    {
        rowBreak = -1;
    }
    else if(option_count % 2 == 0)
    {
        rowBreak = (option_count / 2);
    }
    else
    {
        rowBreak = (option_count + 1) / 2;
    }

    for(i=0; i<rowBreak; i++)
        upperRowObjects.push(options_set[i]);
    return upperRowObjects;
},

并通过以下方式访问它:

{{#each calc_option_set1}}
{{/each}}