[英]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.