【问题标题】:how to know 'each' done or re done in meteor blaze template如何知道在流星火焰模板中完成或重新完成的“每个”
【发布时间】:2018-06-19 16:16:21
【问题描述】:

each 在onRendered 和Tracker.autorun 之后运行(如果foo 正在绑定订阅数据上下文)。

所以我可以t catch thateach` 工作完成后。

如何知道each 是工作完成,还是返工并完成?

未知吗?

下面是一个例子。

<template name="something">
  {{#each foo}}
    <bar>bar</bar>
  {{/each}}
</template>

【问题讨论】:

    标签: meteor meteor-blaze


    【解决方案1】:

    我没有看到真正的用例,但您可以在此处使用不会向渲染输出添加任何内容的助手:

    <template name="something">
      {{#each foo}}
        <bar>bar</bar>
        {{isDone @index foo}}
      {{/each}}
    </template>
    
    Template.something.helpers({
      isDone(index, arr) {
        if (index === arr.length - 1) {
          // this was the last element
          // to be rendered. do whatever
          // you want here
        }
      }
    })
    

    并不是说这不是真正的最佳做法,您应该考虑一下为什么需要了解这一点?如果您的渲染存在性能问题,您需要检查整个模板代码设计并在必要时进行重构。

    【讨论】:

    • 无法保证良好的性能,但对我来说是一个新的尝试。感谢你的回答。 :)
    猜你喜欢
    • 2014-05-07
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 2018-10-03
    • 2017-02-09
    相关资源
    最近更新 更多