我正在尝试做这样的事情:
<template name=week>
{{#each days}} //from an array in helpers with values [0,1,2,3,4,5,6]
{{> day dayOfWeek="<How can I have the value here?>"}}
{{/each}}
<template name>
问题1:如何检索数组的当前值以将其传递给包含的模板?
<template name=day>
{{#autoForm collection=users doc=user ...}}
{{#each days}} //from an array in helpers with values [0,1,2,3,4,5,6]
{{>afFieldInput name='profile.availability.<dayOfWeek>.from'}}
{{/each}}
{{/autoForm}}
<template name>
问题2:如何在名称中动态替换dayOfWeek?
答案 0 :(得分:3)
试试这个:
问题1:
<template name="week">
{{#each days}} //from an array in helpers with values [0,1,2,3,4,5,6]
{{> day dayOfWeek=this}}
{{/each}}
<template name>
问题2:
HTML
<template name="day">
{{#autoForm collection=users doc=user ...}}
{{#each day in days}} //from an array in helpers with values [0,1,2,3,4,5,6]
{{> afFieldInput name=name}}
{{/each}}
{{/autoForm}}
<template name>
ES2015
Template.day.helpers({
name(){
const dayOfWeek = this.dayOfWeek;
return `profile.availability.${dayOfWeek}.from`;
}
});
注意:这是使用最新的Blaze构造和Meteor 1.2的ES2015