0

有点迷失在这里...

我有一个函数可以检查页面上的模板触发器,并在找到时触发模板渲染,首先需要模板(使用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 使用动态模板名称加载不同的模板?

4

1 回答 1

1

尝试以下操作:

...

dyn.f = function (lib_template)  {
  // stuff
};
require(['text!../tx/'+dyn.lib], dyn.f);

...
于 2012-12-23T18:47:30.527 回答