有点迷失在这里......
我有一个函数可以检查页面上的模板触发器,当找到触发模板渲染时,首先需要模板(使用requireJS
),然后构建模板。
我的问题是,我总是请求第一个模板文件,尽管我这样做:
renderTemplateTrigger: function(){
var t = $('.template'),
tl = t.length,
i,
dyn,
el,
config;
if ( tl > 0 ){
for ( i = 0; i < tl; i+=1 ){
el = t[i];
// correct element here
console.log( el );
if ( el.getAttribute("val") === null ){
el.setAttribute("val",true);
// get and parse configuration info
config = el.getAttribute("data-config");
dyn = $.parseJSON( config );
// correct
console.log( dyn );
// load template WILL ALWAYS LOAD THE SAME FILE
require(['text!../tx/'+dyn.lib],
function ( lib_template) {
// stuff
});
}
}
}
}
因此,当两个迭代中的dyn.lib
等于listview
和controlgroup
时,我需要listview
和listview
并且不知道为什么?
问题:
为什么我似乎无法使用带有requireJS的动态模板名称加载不同的模板?
答案 0 :(得分:1)
尝试以下方法:
...
dyn.f = function (lib_template) {
// stuff
};
require(['text!../tx/'+dyn.lib], dyn.f);
...