71104 / jquery-handlebars

A jQuery plugin to render Handlebars.js templates into elements
http://71104.github.io/jquery-handlebars
MIT License
100 stars 39 forks source link

Callback after rendering is done #5

Closed chkorn closed 10 years ago

chkorn commented 10 years ago

While playing with this plugin I had the problem, that after rendering a template I wanted to bind some event-handlers to the newly rendered markup. As I found no obvious way to wait for the rendering/$.get request to finish I added a callback method. Maybe this is something useful for others?

Regards Chris

71104 commented 10 years ago

Hi mate,

actually there is a method for being notified after the rendering is done, and it's registering a handler for the render.handlebars event, which I trigger right after the rendering. The problem is that I forgot to document it. :P

Example:

$('#element').one('render.handlebars', function (template, data) {
    console.dir(template);
    console.dir(data);
}).render('template', {
    data1: false,
    data2: 'lalalala',
    data3: 1234
});

I'm wondering whether to also allow a per-call callback like you did there, but I'm not sure.

Really thank you anyway for pointing out, I'll document the render.handlebars event asap.

chkorn commented 10 years ago

Argh! I was wondering about that trigger-part.. Thank you! :)