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.

some refs: 1, 2, 3


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -