Reputation: 80
I'm working on a project and we're using underscore.js for templating. Is there a way to determine when the template has finished rendering so that I can then cue another function call?
This project includes jQuery but does not include Backbone.js if that helps in your answers.
Thanks! Mike
Upvotes: 0
Views: 540
Reputation: 817120
_.template
returns a function which does the actual evaluation of the template. That function returns the result as string. So whenever the function returns, the rendering is done, it is not asynchronous.
Example from the documentation:
var compiled = _.template("hello: <%= name %>");
compiled({name : 'moe'});
=> "hello: moe"
So you can simple put the next function call after the rendering call:
var compiled = _.template("hello: <%= name %>");
var result = compiled({name : 'moe'});
someOtherFunction();
Upvotes: 1