2013-05-09 26 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; 
}); 

感謝所有。

相關問題