流星on渲染函数后的子模板
Meteor OnRendered function after child Template
父模板onRendered
函数先于子模板调用。如何在呈现子模板后执行父模板函数。
<template name="parent">
{{#each object}}
{{> child}}
{{/each}}
</template>
<template name="child">
<img src="someurl" data-src="someurl">
</template>
现在我需要执行一些文档准备函数所以
Template.parent.onRendered(function() { // doesnt invokes after child template
$("img").unveil();
$(window).trigger("lookup");
});
autorun和afterFlush的组合可能是您需要的。试一下:
Template.parent.onRendered(function() {
this.autorun(function() {
// replace the find with whatever is in your helper
// which returns the children array/cursor
if (Children.find().count()) {
// this should run after the child templates have been rerendered
Tracker.afterFlush(function() {
$('img').unveil();
$(window).trigger('lookup');
});
}
});
});
虽然使用Tracker.afterFlush
是一个产生所需行为的选项,但这样做的最佳方法是仅使用子模板的onRendered
函数。一旦呈现子模板,所需的代码就会执行。
Template.child.onRendered(function() {
this.$('img').unveil();
this.$(window).trigger('lookup');
});
这种方法更自然,并且允许子模板在任何其他模板中使用,而不会"破坏"
相关文章:
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- TypeError:t(..).on不是fullcalendar上的函数
- 我可以将哪些事件附加到jQuery's on()函数
- 在on.change事件之后运行函数
- 将.live或.on添加到jquery函数中
- 类型错误: $(..).查找(..).on 不是一个函数
- 使用 .on 函数运行 jQuery 声明函数
- 如何将socket.on中函数的值保存为全局变量
- Jquery on('单击')..函数只执行一次
- JQuery.click,nor.on(“click”,..)与使用函数创建的ASP.NET和twitter boost
- 为什么在使用.on('click')或.click()时,命名函数后面没有括号
- javascript中的Jquery.on()本机函数
- jquery函数(.on)不起作用
- 角度火:未定义不是一个函数($on方法不存在)
- 组合jquery函数-on()hover/mousenter/mouseleve
- Jquery函数- on元素
- Jquery函数'.on("click")'开始未交
- 使用JQuery中的函数.on()处理事件onfocus
- jQuery函数.on适用于1.8.3,但不适用于1.9.1
- 调用函数on '输入'出版社