Meteor 如何在#每个循环中插入包含数据的额外列?
我有以下模板:Meteor 如何在#每个循环中插入包含数据的额外列?,meteor,handlebars.js,each,Meteor,Handlebars.js,Each,我有以下模板: <body> <table border="1px"> {{> test}} <table> </body> <template name="test"> {{#each items}} <tr> {{> test2}} </tr> {{/each}} </template> <template name="test2"
<body>
<table border="1px">
{{> test}}
<table>
</body>
<template name="test">
{{#each items}}
<tr>
{{> test2}}
</tr>
{{/each}}
</template>
<template name="test2">
<td>{{name}}</td><td>{{lastruntime}}</td><td>{{result}}</td><td>{{blaat}}</td>
</template>
现在,{{blaat}}不是文档的一部分,但需要根据单行中的数据填充数据。我做了很多尝试,但是找不到如何访问/填充{{blaat}}标记。有人吗?您可以通过添加blaat
属性来修改每个文档。然后可以返回修改过的文档数组,而不是返回光标。例如:
Template.test.items=function(){
返回ScheduledTasks.find().map(函数(项){
item.blaat=item.name+item.result;
退货项目;
});
};
然后,blaat
属性将可用于模板,就像name
和result
一样
可选地,如果您认为<代码> BLAAT 属性应在每次检索到计划任务时出现<强>始终> /强>,那么您可以考虑向集合添加A。
ScheduledTasks = new Meteor.Collection("scheduledTasks");
if (Meteor.isClient) {
Template.test.items = function () {
return ScheduledTasks.find({});
}
};