var plain_array = [1, 2, 3, 4, 5, 6, 7]
如何显示Meteor Handlebars中的所有元素?
{{#each plain_array}}
# What to put here to get the elements?
{{/each}}
Run Code Online (Sandbox Code Playgroud)
(这个问题类似:把手:如何访问数组?但是与其他问题不一样,假定一个对象数组.)
如何在Meteor中将数组值加载到模板变量?请看下面的代码并建议我该怎么做?
HTML代码:
<template name="header">
<div class="header">
{{#each alphabets}}
<div class="alphabets">{{this}}</div>
{{/each}}
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
JS代码:
//the below array values are load dynamically above template
var Alphas = ['ALL',
'A', 'B', 'C', 'D','E', 'F',
'G', 'H', 'I', 'J','K', 'L',
'M', 'N', 'O', 'P','Q', 'R',
'S', 'T', 'U', 'V','W', 'X',
'Y', 'Z'
]
Template.header.alphabets = function (i)
{
return Alphas[i];
};
Run Code Online (Sandbox Code Playgroud)