Meteor Template.onRendered or Template.rendered for using a jquery library? -
i want use chosen(a jquery library) meteor , need use code:
$('#ship').chosen();
i tried using .onrendered need wait, if want work
template.createtradeform.onrendered(function(){ //strange bug, need wait here or doesn't work.. settimeout(function(){ $('#ship').chosen(); }, 2000); });
same problem solution:
template.createtradeform.rendered = function(){ //here again, need wait or doesn't work settimeout(function(){ $('#ship').chosen(); }, 2000); };
is there other solutions problem? settimeout isn't here.
edit helper requested
template.createtradeform.helpers({ 'getships': function(){ return ship.find() } });
wrap code inside meteor.defer
, this:
template.createtradeform.onrendered(function(){ meteor.defer(function(){ $('#ship').chosen(); }); });
meteor.defer
corresponds settimeout
of 0
, it's not in docs. typically solve cases in dom you're depending on has not yet rendered.
Comments
Post a Comment