按照我所知,marionette.template
接受jquery selector
或compiled template string
。如何将函数分配给marionette.template
如果我写这样以下列方式代码,做工精细
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,"");
}
});
注:commonFunctions.templateCompilation()
接受templateId
作为第一个参数,作为data
第二个参数。它将编译handlebars template
并返回编译模板。
如果我将该返回值分配给template
,则正常工作。
我想为模板数据,所以我传递function
到template like in the following way.
exports.ProductInfoView=Backbone.Marionette.ItemView.extend({
domInfo:{
mainTemplateId:"tagProductListTpl",
tableTemplateId:"taginfoViewTpl"
},
template:function(){
return 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,"");
}
});
这种方式也工作正常,如果你观察我硬编码templateId("tagProductListTpl")
内function.But我不希望这样的。我想用this.domInfo.mainTemplateId
而不是硬编码。这样它不能正常工作。
这是抛出错误。我知道它超出了范围。但我怎么能实现这一点。
任何人都可以帮助我。
谢谢。