Meteor - 在模板参数中传递变量
Meteor - Pass variable in templates arguments
我正在尝试做这样的事情:
<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?
试试这个:
问题 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
我正在尝试做这样的事情:
<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?
试试这个:
问题 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