behold, a backbone view render call:
render: function() {
$(this.el).html(this.template({title: 'test'})); //#1
this.renderScatterChart();
return this;
},
so, I call a standard render at #1. and then, i call a method [this time, it is a wrapper for charting lib] that looks for a div. the div is rendered by the render call. but at this point, it is not attached to the DOM yet (right?). so the chart call sadly dies.
what is the pattern for this? i’d love hear that there is a post-render callback. i’ve tried a few hacks around this, and sometimes i get the chart to work, but events don’t bind.
My usual approach for this sort of thing is to use
setTimeoutwith a timeout of zero to arrange for something to happen once the browser gets control again. Try this:Or, if
renderScatterChartis already bound to the appropriatethis:You can also use
_.deferif you want to be more explicit about what you’re up to:So you could also do it like this: