在Blaze Template for Meteor中有变量

时间:2015-06-02 17:27:02

标签: javascript node.js meteor meteor-blaze

从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中实现这一点。

2 个答案:

答案 0 :(得分:0)

您可以在帮助程序中迭代数组,并在将结果返回到模板之前以特殊方式标记每个第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>

答案 1 :(得分:0)

谢谢@David。

我认为应该使用带有溢出功能的CSS的网格,并且响应比HTML表格。