I have an iron route defined like this (pay attention to onAfterAction and 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})};
}
});
The function initProfileComponent wishes to find using document.querySelectorAll elements created by meteor/mustache publish mechanism, that is why is called in onAfterAction, but obviously it doesn't work, since, when it is called the elements are not yet rendered.
The templates are defined like this :
<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>
Other than onAfterAction which does "buritos" for my use case, where/how can one define an callback that ensures that the template was fully rendered. Or, to what should I subscribe?