用于meteor.js 的模板加载事件 [英] Template onload event for meteor.js

查看:18
本文介绍了用于meteor.js 的模板加载事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道meteor 会为DOM 元素公开诸如click"之类的事件,但我想知道在加载模板或部分时是否会触发加载事件?我将如何做到这一点?

I know meteor exposes events such as "click", for DOM element but I'm wondering if there's a load event that's fired when a template or partial is loaded? How would I accomplish this?

谢谢.

推荐答案

对于 Meteor 从 0.4.0 开始预览,您可以使用 Template.myTemplate.created.

For Meteor starting from 0.4.0 preview, you can use Template.myTemplate.created.

Template.myTemplate.created 中,DOM 还没有准备好.

In Template.myTemplate.created the DOM is not ready however.

如果您需要操作 DOM,您可能需要使用 Template.myTemplate.rendered 改为使用布尔值来跟踪 Template 对象中的状态,如下所示:

If you need to manipulate the DOM, you might want to use Template.myTemplate.rendered instead and use a boolean value to track the state within the Template object like this:

Template.myTemplate.rendered = function() {
    if(!this._rendered) {
      this._rendered = true;
      console.log('Template onLoad');
    }
}

这篇关于用于meteor.js 的模板加载事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆