[英]Having variables in Blaze Template for Meteor
从Meteor JS的Template.helper中,我得到了一个数组,我可以使用它
{{#each array_result}}
{{value}}
{{/each}}
我想要的是
<table>
{{#each array_result}}
{{if count%4 ===0}}</tr><tr>
<td>{{value}}</td>
{{count++}}
{{/each}}
</table>
无论如何,我可以在HTML中实现这一点。
您可以在帮助程序中遍历数组,并以某种特殊方式标记每个第4个项目,然后将结果返回到模板:
Template.myTemplate.helpers({
array_result: function() {
// fetch an array of docs/items somehow
var docs = SomeCollection.find().fetch();
// iterate over them and mark each 4th item as "awesome"
_.each(docs, function(doc, index) {
if (index % 4 === 0)
doc.isAwesome = true;
});
// return the modified documents
return docs;
}
});
然后,您的模板可能如下所示:
<table>
{{#each array_result}}
{{#if isAwesome}}
...
{{else}}
...
{{/each}}
</table>
谢谢@大卫。
我认为应该将Grids与CSS一起使用,该CSS具有溢出功能并且比HTML表格具有响应能力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.