2016-02-11 51 views
1

中的每个项目我试图访问我的代码中的数组值,以便我可以使用它们,但我不知道如何。由于阵列{{display item}}

var footerButtons = ['NO', 'EXTRA', 'YES']; 
 

 
<template name="footer"> 
 
    {{#each footerButtons}} 
 
    <h1> 
 
     <button class="col-xs-2 mainMenu" type="button">{{what should go here?}}</button> 
 
    </h1> 
 
    {{/each}} 
 
</template>

回答

2

你可以定义你footerButtons帮手如下 -

Template.footer.helpers({ 
    footerButtons() { 
    return [{text: 'NO'}, {text: 'EXTRA'}, {text: 'YES'}]; 
    } 
}); 

然后在你的模板,你可以访问该值,如下图所示。

<template name="footer"> 
    {{#each footerButtons}} 
    <h1> <button class="col-xs-2 mainMenu" type="button">{{text}}</button> </h1> 
    {{/each}} 
</template> 
2

{{.}}{{this}}是你在找什么。这指的是数组中的当前对象/元素。