2015-08-26 64 views
15

我們有一個CMS,所以我沒有進入HTML頁面的頭部,我們的extjs實現獲取rendert。所以我不得不做一個workround這是這樣的:ExtJs minify獲取忽略

Ext.local = {}; 
    var lang = { 
     initLang: function (revisionNr) { 
      var local = localStorage.getItem('localLang') 
      if (!local) { 
       AjaxHandlerByClass('ajax/lang/webuser/init', {}, this.loadLangRemote); 
      } else { 
       local = JSON.parse(local); 
       if (local.revisionNr == config.revisionNr && local.lang == config.lang) { 
        console.log('loading local lang variables'); 
        if (local.date < new Date().getTime() - (24 * 60 * 60 * 1000) * 2) {//2 day caching time before retry 
         delete window.localStorage.localLangBackup; 
        } 
        this.loadLangLocal(local); 
       } else { 
        delete window.localStorage.localLang; 
        AjaxHandlerByClass('ajax/lang/webuser/init', {}, this.loadLangRemote); 
       } 
      } 
     }, 
     loadLangRemote: function (data) { 
      data.revisionNr = config.revisionNr; 
      data.lang = config.lang; 
      data.date = new Date().getTime(); 
      lang.loadLangLocal(data); 
      localStorage.setItem('localLang', JSON.stringify(data)); 
     }, 
     loadLangLocal: function (data) { 
      var jsElm = document.createElement("script"); 
      jsElm.type = "application/javascript"; 
      jsElm.src = 'js/freetext-deploy.min.js?rev={/literal}{$revisionNr}{literal}'; 

      document.getElementsByTagName('head')[0].appendChild(jsElm); 

      Ext.Date.defaultFormat = 'd-m-Y'; 
      if (!debug) { 
       Ext.Loader.config.disableCaching = true; 
      } 


      Ext.application({ 
       name: 'freetextOrder', 
       appFolder: 'modules/extjs/freetextOrder/app', 
       controllers: [ 
        'Main' 
       ], 
       launch: function() { 

        var freetextOrder = Ext.create('Ext.container.Container', { 
         renderTo: Ext.get('freetextOrderDiv'), 
         layout: 'fit', 
         id: 'catalogAdministrationDiv_ext', 
         height: 800, 
         cls: 'x-dig-override', 
         items: [Ext.create('freetextOrder.view.base.MainView', {})], 
         layout:'fit' 
        }); 
       } 
      }); 
      Ext.local = data; 
     } 
    }; 
    lang.initLang(); 

問題我有的是,縮小版本被完全忽略。我看到它在http請求上加載,但extjs忽略它們....甚至難以看到對象正在創建後包括(通過控制檯日誌)

任何任何想法如何我可以實現這個?

回答

4

因爲我看到沒有找到答案,所以我張貼我自己在這裏,我想出了。

因爲我可以爲上帝的愛沒有加載該死的東西我重構了加載程序並將其導出到Js中。文件。至此我需要並在代碼中稍後調用。

出口lang.js文件:

Ext.define('Lang', { 
    singleton: true, 
    ApplicationConf: null, 
    Launch: function (launchConfig) { 

     this.ApplicationConf = launchConfig; 

     var local = localStorage.getItem('localLang'); 
     var me = this; 

     this.loadLangRemote = function (data) { 
      debugger; 
      data.revisionNr = config.revisionNr; 
      data.lang = config.lang; 
      data.date = new Date().getTime(); 
      me.loadLangLocal(data); 
      localStorage.setItem('localLang', JSON.stringify(data)); 
     }; 
     this.loadLangLocal = function (data) { 
      Ext.local = data; 
      Ext.lang = function (langId) { 
       if (Ext.local[langId]) { 
        return Ext.local[langId]; 
       } 

       delete window.localStorage.localLang; 
       localStorage.setItem('localLangBackup', true); 
       return langId; 
      } 
      Ext.application(me.ApplicationConf); 
     }; 

     if (!local) { 
      Ext.Ajax.request({ 
       url: 'ajax/lang/webuser/init', 
       params: { 
        sid: sid, 
       }, 
       success: function (data) { 
        debugger; 
        me.loadLangRemote(Ext.JSON.decode(data.responseText)); 
       } 

      }) 
     } else { 
      local = JSON.parse(local); 
      if (local.revisionNr == config.revisionNr && local.lang == config.lang) { 
       console.log('loading local lang variables'); 
       if (local.date < new Date().getTime() - (24 * 60 * 60 * 1000) * 2) {//2 day caching time before retry 
        delete window.localStorage.localLangBackup; 
       } 
       debugger; 
       me.loadLangLocal(local); 
      } else { 
       delete window.localStorage.localLang; 
       Ext.Ajax.request({ 
        url: 'ajax/lang/webuser/init', 
        params: { 
         sid: sid, 
        }, 
        success: function (data) { 
         me.loadLangRemote(Ext.JSON.decode(data.responseText)); 
        } 
       }) 
      } 
     } 

    }, 
}) 

而重要的是,增添

Ext.onReady(function() { 
      Lang.Launch({ 
       name: 'catalogAdministration', 
       appFold.... 

在代碼中的啓動函數的調用,bacause它會一直在運行時不定義。我首先將文件添加到縮小文件,然後調用Lang.Launch代替Ext.Application。

希望somone有使用我的解決方案:)