使用帮助程序自动打印Meteor集合的字段,而不指定其名称
是否可以使用助手自动打印Meteor集合的字段而不指定它们 假设我开始有一个助手,它返回存储在表中的对象集合,如下所示:使用帮助程序自动打印Meteor集合的字段,而不指定其名称,meteor,meteor-blaze,spacebars,meteor-helper,Meteor,Meteor Blaze,Spacebars,Meteor Helper,是否可以使用助手自动打印Meteor集合的字段而不指定它们 假设我开始有一个助手,它返回存储在表中的对象集合,如下所示: {{ #each CollectionData }} <thead> <tr> <th>Code</th> <th>Description</th> </tr> </thead> <tbody>
{{ #each CollectionData }}
<thead>
<tr>
<th>Code</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<Tr class="object-row">
<Td> {{code}} </ td>
<Td> {{description}} </ td>
</tr>
</tbody>
...
{{/each}}
现在,我将使助手自动生成表列和值对于显示检查为true的集合字段,无需手动指定{{code}}、{{description}等等,例如:
// Items is the name of the possible collection
Schema.items var = {
fields {
code: {
columnName: "code",
show: false,
},
description: {
columnName: "description",
show: false,
},
otherField {
columnName: "foo",
show: false,
}
}
}
{{ #each CollectionData }}
<thead>
<tr>
{{print each column where show check is == true, without manually specifing any name}}
</tr>
</thead>
<tbody>
<Tr class="object-row">
{{print the value of the column, for this record, where show check is == true, without specifing its name}}
</tr>
</tbody>
...
{{/each}}
{{{#每个集合数据}
{{打印show check==true的每一列,而不手动指定任何名称}
{{打印此记录的列的值,其中show check==true,不指定其名称}
...
{{/每个}}
有什么方法可以做到这一点吗?最简单的方法是为每个TD创建一个模板,比如
<thead>
<tr>
{{#each fetchColumnHeaders}}
{{> columnHeader }}
{{/each}}
</tr>
</thead>
{{ #each CollectionData }}
<tbody>
<Tr class="object-row">
{{#each fetchColumnItems}}
{{> columnItem}}
{{/each}}
</tr>
</tbody>
{{/each}}
<template name="columnHeader">
<th>{{label}}</th>
</template>
<template name="columnItem">
<td>{{label}}</td>
</template>
{{#每个fetchColumnHeader}
{{>columnHeader}
{{/每个}}
{{{#每个收集数据}
{{{#每个项目}
{{>columnItem}
{{/每个}}
{{/每个}}
{{label}}
{{label}}
然后,您可以编写模板帮助程序来返回列标题,以及基于您的模式的各种项目。最简单的方法是为每个TD创建一个模板,如
<thead>
<tr>
{{#each fetchColumnHeaders}}
{{> columnHeader }}
{{/each}}
</tr>
</thead>
{{ #each CollectionData }}
<tbody>
<Tr class="object-row">
{{#each fetchColumnItems}}
{{> columnItem}}
{{/each}}
</tr>
</tbody>
{{/each}}
<template name="columnHeader">
<th>{{label}}</th>
</template>
<template name="columnItem">
<td>{{label}}</td>
</template>
{{#每个fetchColumnHeader}
{{>columnHeader}
{{/每个}}
{{{#每个收集数据}
{{{#每个项目}
{{>columnItem}
{{/每个}}
{{/每个}}
{{label}}
{{label}}
然后,您可以编写模板帮助程序来返回列标题以及基于您的模式的各种项目