javascript - how to assign function to marionette.template -
as per know, marionette.template
take either jquery selector
or compiled template string
.
if write code in next way, working fine
exports.productinfoview=backbone.marionette.itemview.extend({ dominfo:{ maintemplateid:"tagproductlisttpl", tabletemplateid:"taginfoviewtpl" }, template:commomfunctions.templatecompilation("tagproductlisttpl",""), onrender:function(){ this.templatingproductinformation(); }, modelevents:{ "change:currentjson":"templatingproductinformation" }, templatingproductinformation:function(){ console.log(this.el); //this.el.innerhtml=commomfunctions.templatecompilation(this.ui.maintemplateid,""); } });
note :commonfunctions.templatecompilation()
take templateid
first argument , data
sec argument. compile handlebars template
, homecoming compiled template.
if assign homecoming value template
, working fine.
i want create info templating,so passing function
template in next way.
exports.productinfoview=backbone.marionette.itemview.extend({ dominfo:{ maintemplateid:"tagproductlisttpl", tabletemplateid:"taginfoviewtpl" }, template:function(){ homecoming commomfunctions.templatecompilation("tagproductlisttpl",""); }, onrender:function(){ this.templatingproductinformation(); }, modelevents:{ "change:currentjson":"templatingproductinformation" }, templatingproductinformation:function(){ console.log(this.el); //this.el.innerhtml=commomfunctions.templatecompilation(this.ui.maintemplateid,""); } });
this way working fine, if observer hard coded templateid("tagproductlisttpl")
within function.but don't want that. want utilize this.dominfo.maintemplateid
instead of hard coding. way it's not working fine.
it's throwing error. know it's out of scope. how can achive this.
can help me.
thanks.
i advise rewrite marionette.templatecache.prototype.compiletemplate
responsible template compilation. @ this post, there same issue.
marionette.templatecache.prototype.compiletemplate = function (yourrawtemplate) { // in case if template function if (_.isfunction(yourrawtemplate)) { homecoming yourrawtemplate; } else { homecoming handlebars.compile(yourrawtemplate); } };
and if loading template files remote server need rewrite backbone.marionette.templatecache.prototype.loadtemplate
. here example:
marionette.templatecache.prototype.loadtemplate = function ( templateid ) { var template = '', templateurl = 'path_to_your_template/' + templateid + '.html'; // loading template synchronously. backbone.$.ajax( { async : false, url : templateurl, success : function ( templatehtml ) { template = templatehtml; } } ); homecoming template; };
javascript backbone.js handlebars.js marionette
No comments:
Post a Comment