多个表中的{{#each}}标记

时间:2016-01-20 23:28:25

标签: meteor

我没有做一些非常高效的事情。我有很多需要从这样的集合中填写的表格(只显示了两个):

<div class="row">
<div class="col s3" id="change-code" style="background-color: #22313f; color: #fff; height: 150px; position: relative; top: -100px">
  <p class="grid-title">code:</p>
  {{#each demographic}}
  <div style="font-size: 5.0em; line-height: 100%; font-weight: 600">{{Code}}</div>
  {{/each}}
</div>

<div class="col s4" id="name-address-change" style="background-color: #1e8bc3; color: #fff; height: 200px">
  <p class="grid-title">Name/Address:</p>
  {{#each demographic}}
  <p>{{FullName}}</p>
  <p>{{Address}}</p>
  <p>{{City}}, {{State}} {{Zip}} {{CountryCode}}</p>
  <p>{{Country}}</p>
  {{/each}}
</div>

<div class="col s5" id="contact-change" style="background-color: #34495e; color: #fff; height: 200px">
  <p class="grid-title">Contact:</p>
  {{#each demographic}}
  <p>Hphone: {{Hphone}}</p>
  <p>Cphone: {{Cphone}}</p>
  <p>SN: {{Email}}</p>
  <p>SS: {{StudentEmail}}</p>
  {{/each}}
</div>

看起来每次调用{{#each demographic}}时,它都会重新运行模板助手,并再次查询集合:

Template.clientGrid.helpers({

  'demographic': function () {
  var fullNameD = Session.get('clientName');
  return Demographic.find({ FullName: fullNameD});
},

  'programs': function () {
  var fullNameP = Session.get('clientName');
  return Programs.find({ FullName: fullNameP});
  }
});

好像帮助者只需要运行一次。我怎么能这样做?

0 个答案:

没有答案