【发布时间】:2015-10-26 03:25:26
【问题描述】:
我有这样定义的铁路线(注意onAfterAction和initProfileComponent)
var initProfileComponent = function () {
var elements = document.querySelectorAll('.sliderComponent');
//... do stuff and decorate the elements
}
Router.route('newProfile', {
path: '/new-profile/:_id',
onAfterAction: function () {
initProfileComponent();
},
data: function () {
return {profile: Profile.findOne({_id: this.params._id})};
}
});
函数initProfileComponent希望使用由meteor/mustache发布机制创建的document.querySelectorAll元素找到,这就是为什么在onAfterAction中调用,但显然它不起作用,因为当它被调用时尚未渲染。
模板是这样定义的:
<template name="newProfile">
<div class="main-title new-profile">
new profile
</div>
{{#each profile.properties}}
{{> sliderComponent}}
{{/each}}
</template>
<template name="sliderComponent">
<div class="sliderComponent dragdealer">
<div class="handle">{{label}}</div>
</div>
</template>
除了onAfterAction 为我的用例执行“buritos”之外,在哪里/如何定义一个回调以确保模板完全呈现。或者,我应该订阅什么?
【问题讨论】:
标签: javascript meteor iron-router