Meteor中的把手为每个助手打电话回叫?

Bor*_*tov 1 handlebars.js meteor

使用此内容创建手柄模板时:

<template name="list">
  {{#if array}}
    <ul>
      {{#each array}}
        <li>{{item.name}}</li>
      {{/each}}
    </ul>
  {{else}}
    No items.
  {{/if}}
</template>
Run Code Online (Sandbox Code Playgroud)

和模板回调.

Template.list.array = function() {
  // Some queries here + logic to build your array.
};
Run Code Online (Sandbox Code Playgroud)

你的模板回调将被调用两次..对于if Helper和每个 Helper.这不是性能问题吗?

谢谢.

Xya*_*and 6

您可以将其重写为:

<template name="list">
  {{#with array}}
    <ul>
      {{#each .}}
        <li>{{item.name}}</li>
      {{/each}}
    </ul>
  {{else}}
    No items.
  {{/with}}
</template>
Run Code Online (Sandbox Code Playgroud)