我optionData.js如下:爲什麼#each標記不接受數組?
"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."
如何通過迭代的方法返回的數組了嗎?任何方式我可以將它分配給一個變量,然後使用它?請幫忙...
可否請你看看這個答案:http://stackoverflow.com/questions/21234947/meteor-handlebars-how-to-access-a- plain-array –
and this link:http://handlebarsjs.com/#iteration –
[Add to Array jQuery]的可能重複(http://stackoverflow.com/questions/5861859/add-to-array-jquery) –