I use a basic template to render my templates, its fetchTemplate method caches processed templates.
I would like to run some additional code on the displayed content, for example, initialize accordions, etc., but using a compiled async template to do this is more difficult than I thought.
Here is an example:
Duel.Views.Home = Backbone.View.extend({
template: "/templates/duel_home.jade",
render: function() {
var view = this;
statusapp.fetchTemplate(this.template, function(tmpl) {
$(view.el).html( tmpl({duels: view.collection.toJSON()}) );
view.postrender();
});
return this;
},
postrender: function() {
$('#duel-new').each(function() {
console.log('Found something')
});
}
});
In addition to the above, I use the view handler described in http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/
This I do something like
var view = Duel.Views.Home({model: mymodel})
viewHandler('#content').showView(view)
it causes
$('#content').html(view.render().el)
, , , postrender . , , , postrender, view.el DOM, $(this.el) , $( '# duel-new'). each() "void".
, postrender viewHandler, , . , postrender , , .
, ? , , , , , $('#tabs').tabs()?
fetchTemplate :
fetchTemplate: function(path, done) {
window.JST = window.JST || {};
if (JST[path]) {
return done(JST[path]);
}
return $.get(path, function(contents) {
var tmpl = jade.compile(contents,{other: "locals"});
JST[path] = tmpl;
return done(tmpl);
});
},