Template 实例的created 和rendered 回调有什么区别? [英] What is the difference between created and rendered callback of Template instance?

查看:47
本文介绍了Template 实例的created 和rendered 回调有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

官方文档

[rendered] 在 Template.myTemplate 的实例被调用时调用一次渲染成DOM节点,第一次放入文档.

[rendered] is called once when an instance of Template.myTemplate is rendered into DOM nodes and put into the document for the first time.

[created] 回调在评估模板的逻辑之前被调用第一次.

[created] callback is called before your template's logic is evaluated for the first time.

有点让我困惑.它们之间究竟有什么区别?一旦创建"模板实例,它们似乎都被调用.如果有,它们各自的用途是什么?附言我发现 Meteor 文档的很大一部分缺乏可靠的示例,这对于初学者来说确实很难理解.

kind of confuses me. What exactly is the difference between them? They both seem to be called once a template instance is "created". If so, what are their respective usages? P.S. I find that a big portion of the Meteor documentation lacks solid examples, which is really hard for beginners to understand.

推荐答案

模板 rendered 回调在 DOM 呈现在屏幕上后触发.created 回调在模板已实例化但尚未呈现时触发.

The template rendered callback is fired after the DOM is rendered on screen. The created callback is fired when the Template is instantiated but not yet rendered.

您可以使用 rendered 回调来更改页面上的任何内容.例如,如果您使用 select2 您需要将

发送“验证码”获取 | 15天全站免登陆