2012-05-02 26 views
0

我有一個由Sencha Architect 2創建的小應用程序。我已經注意到好幾次了,我可以很好地覆蓋Controller和Application對象的onLaunch,該函數永遠不會被調用。我使用的是試用版2.0.0,建立412這是在應用程序代碼:Sencha Architect 2:onLaunch從未調用

Ext.Loader.setConfig({ 
    enabled: true 
}); 

Ext.application({ 
    views: [ 
     'MyContainer', 
     'MyGridPanel' 
    ], 
    autoCreateViewport: true, 
    name: 'MyApp', 

    onLaunch: function() { 
     var container = Ext.getCmp ('glbContainer'); 

     var cfg = [ 
     { dataIndex: 'ID', text: 'ID' }, 
     { dataIndex: 'DISPLAYNAME', text: 'Displayname' } 
     ]; 

     var theGridPanel = this.getComponent ('theGridPanel'); 

     var config = []; 


     for (var jj=0; jj<cfg.length; jj++) { 
      var configElem = {}; 
      configElem.xtype = 'gridcolumn'; 
      configElem.dataIndex = cfg [jj].dataIndex; 
      configElem.text = cfg [jj].text; 
      configElem.width = 200; 
      config.push (configElem); 
     } 

     alert (config.length); 

     theGridPanel.reconfigure (config); 

    } 

}); 

回答

2

我不認爲我們有一個onLaunch方法重寫。它應該是launch。看看文件。應用程序或控制器類沒有onLaunch屬性。從文檔引用:

啓動方法:由控制器的應用程序在 之後立即調用應用程序自己的啓動函數。這通常是 運行任何必須在應用UI初始化爲 後運行的邏輯的好地方。另請參閱在應用程序的 啓動函數之前調用的init。

實施例:

Ext.application({ 
    name: 'MyApp', 
    launch: function() { 
     Ext.create('Ext.container.Viewport', { 
      items: { 
       html: 'My App' 
      } 
     }); 
    } 
}); 
+0

嗨,我是非常願意聽從你的意見,我一定會努力推出,但是應用程序和控制器都有onLaunch:http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Application。文檔說:「這是一個模板方法,是這個類的功能鉤子,隨意在子類中覆蓋它。」 – kaidentity

+0

啊!我徹底的錯誤!現在我明白你在做什麼了! –

+0

但推出正常工作...我只是試圖忘記我曾嘗試onLaunch之前...... – kaidentity

2

發射是在這裏使用的正確的方法。

雖然應用程序是一個Ext.app.Controller它並不總是做一個控制器。另外請注意,您在此處不使用Ext.define來定義您的應用程序,您不應該這樣做。不過你正在調用一個方法Ext.application({config});

正確的方式來設置應用程序的啓動方法

Ext.application({ 
    name: 'MyApp', 
    controllers: [ 
     'MyController' 
    ], 

    launch: function() { 

    } 

}); 

正確的方法來設置控制器的啓動方法

Ext.define('MyApp.controller.MyController', { 
    extend: 'Ext.app.Controller', 

    onLaunch: function() { 

    } 

}); 
相關問題