2013-05-09 57 views
0

我开始一个应用程序(我是新的requirejs)requirejs应用程序的单例模型...基本上我传递模板数组到我的工具js,并分配模板相应的视图...Requirejs - 使用单例对象,无法获得返回的模板

我使用:

app.js,singleton.js(返回对象),用于实现索引页面模板index.js,分配模板相应的视图公用事业...我得到一个结果为“function(n){return e.call(this,n,w)}” - 我明白了这一点,我的方法是错误的..可以任何一次给我正确的方式给我..或突出我错了我做什么pelase ..?

在此先感谢..

这是我所有的js文件:

app.js: -

requirejs.config({ 
    baseUrl: 'js', 
    paths: { 
     "jquery" : 'lib/jquery-1.9.1.min', 
     "underscore": "lib/underscore-min", 
     "backbone" : "lib/backbone-min", 
     "singleton" : "utils/singleton", 
     "model"  : "models/model", 
     "index"  : "views/index", 
     "utils"  : "utils/utils", 
    }, 
    shim:{ 
     "underscore":{ 
      exports: '_' 
     }, 
     "backbone":{ 
      exports: 'Backbone', 
      deps:['underscore'] 
     }, 
     "utils" : { 
      deps:['index'], 
      deps:['model'] 
     } 
    } 
}); 

require(["jquery","underscore","backbone","singleton","utils","index"],function ($,_,Backbone,obj) { 
    obj.makeTemp(['index']); 
}); 

singleton.js(刚返回的对象)

define(function() { 
    var EDMS = EDMS || {}; 
    return EDMS; 
}) 

utilities.js(我指定模板)

define(["underscore", "singleton","model","index"],function (_,obj,model) { 

    var EDMS = obj || {}; 

     EDMS.makeTemp = function(views){ 
      $.each(views, function(index,view){ 
       if(view){ 
         var temp = $.get('templates/' + view + '.html') 
         .done(function(data){ 
          EDMS[view].prototype.template = _.template(data); 
          new EDMS.index; 
         }) 
       }else{ 
         console.log("No template found!") 
        } 

       }); 
     } 

    return EDMS; 

}) 

最后我index.js,我应该想拿到模板,这是由utilities.js分配

define(["singleton","underscore","backbone","utils"],function (obj,_,Backbone) { 

     var EDMS = obj || {}; 

     EDMS.index = Backbone.View.extend({ 
      initialize:function(){ 
       console.log(this.template); 
          error i am getting as "function (n){return e.call(this,n,w)} " 
      } 
     }); 

}) 

回答

0

这是为我工作:

define(['singleton',"underscore","backbone"],function (obj,_,Backbone) { 

    window.EDMS = obj || {}; 

    var temps = function(views){ 
     var tempts = []; 
     $.each(views, function(i,view){ 
      var data = $.get("templates/"+views+".html"); 
      data.done(function(res){ 
       EDMS[views].prototype.template = _.template(res); 
       new EDMS.index; 
      }); 
     }) 
    }; 
    return temps; 
}); 

感谢所有。

相关问题