【问题标题】:Pass arguments to helpers in Spacebars Template Inclusion将参数传递给空格键模板包含中的助手
【发布时间】:2018-05-26 17:54:19
【问题描述】:

假设我有一个包含模板的模板

<template name="Profile_Page">
    {{> Text_Form_Control value=helper_function}}
</template>

我想从我的辅助函数返回一个数组,并根据调用辅助函数的时间访问特定的索引。但是,我不能简单地键入 helper_function[0] 来访问数组中的第一个插槽。如果数组的索引是从辅助函数传回的,通常如何访问它?

【问题讨论】:

  • 试试helper_function.0

标签: meteor spacebars


【解决方案1】:

理想情况下,如果助手返回一个数组,您希望空格键使用{{#each foo}} 或{{#Each bar in foo}} 对其进行迭代

否则,如果您希望助手返回不同的单条数据,请传入一个参数:

Template.myTemplate.helpers({
  myHelper(index) {
    var myArray = ['foo', 'bar'];
    return myArray[index];
  }
});

模板:

<template name="Profile_Page">
  {{> Text_Form_Control value=(helper_function 0)}}
</template>

【讨论】:

    猜你喜欢
    • 2015-08-25
    • 2015-09-02
    • 2015-10-10
    • 2015-07-10
    • 2015-08-27
    • 2016-01-19
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多