頁面加載完畢后,Ext.application方法中l(wèi)aunch配置選項中指定的函數(shù),通常是應用程序啟動后立即執(zhí)行的一些函數(shù),將這些函數(shù)放在這里。
在編寫MVC模式的應用程序的時候,處理launch函數(shù)之外,也可以在應用程序啟動后,將所需執(zhí)行的處理放置在每一個控制器的init函數(shù)中。該函數(shù)在Ext.application方法中l(wèi)aunch函數(shù)之前被調(diào)用。如果使用設備配置文件的話,可以在每個設備配置文件中定義一個launch函數(shù),這些launch函數(shù),在每一個控制器的init函數(shù)之后,Ext.application方法中l(wèi)aunch函數(shù)之前被調(diào)用。
應用程序啟動時函數(shù)的調(diào)用順序:
1. 每個控制器中的init函數(shù)
2. 設備配置文件中的launch函數(shù)(不清楚這個設備配置文件指的是什么)
3. 應用程序的launch函數(shù)
4. 每個控制器中的launch函數(shù)
/*******************************************************************************************************************************/
下面是一個事例,目的是看看各個函數(shù)執(zhí)行的順序:結果應該是,先執(zhí)行controller/Main.js中的init()函數(shù),在執(zhí)行app.js中的launch函數(shù),最后執(zhí)行controller/Main.js中的launch()函數(shù)
/*******************************************************************************************************************************/
app.js
Ext.Loader.setPath({
'Ext': 'touch/src', 'Oreilly': 'app' }); //</debug> Ext.application({
name: 'Oreilly', requires: [
'Ext.MessageBox' ], views: ['Main'],
controllers:['Main'], icon: {
'57': 'resources/icons/Icon.png', '72': 'resources/icons/Icon~ipad.png', '114': 'resources/icons/Icon@2x.png', '144': 'resources/icons/Icon~ipad@2x.png' }, isIconPrecomposed: true,
startupImage: {
'320x460': 'resources/startup/320x460.jpg', '640x920': 'resources/startup/640x920.png', '768x1004': 'resources/startup/768x1004.png', '748x1024': 'resources/startup/748x1024.png', '1536x2008': 'resources/startup/1536x2008.png', '1496x2048': 'resources/startup/1496x2048.png' }, launch: function() {
// Destroy the #appLoadingIndicator element //Ext.fly('appLoadingIndicator').destroy(); // Initialize the main view
Ext.Viewport.add(Ext.create('Oreilly.view.Main'));//這里調(diào)用了view視圖下的Main.js alert("總程序的launch()方法被調(diào)用"); }, onUpdated: function() {
Ext.Msg.confirm( "Application Update", "This application has just successfully been updated to the latest version. Reload now?", function(buttonId) { if (buttonId === 'yes') { window.location.reload(); } } ); } }); ------------------------------------------------------------------------------------------------------------------------------------------------------------ 當調(diào)用Ext.application方法中l(wèi)aunch函數(shù)之前頁面已經(jīng)加載好了
![]() ![]() ![]() app/view/Main.js 這里定義了兩個按鈕,以及單擊按鈕時彈出的alert
Ext.define('Oreilly.view.Main',{
extend:'Ext.Container', xtype:'mainview', config:{ id:'myPanel', layout:'fit', fullscreen:true, items:[{ id:'mytoolbar', docked:'top', xtype:'toolbar', items:[ { xtype:'button', id:'myButton1', text:'測試按鈕1', handler:function(){ alert('測試按鈕1'); } },{ xtype:'button', id:'myButton2', text:'測試按鈕2', handler:function(){ alert('測試按鈕2'); } } ] }] } }); ------------------------------------------------------------------------------------------------------------------------------------
控制器里的Main.js
app/controller/Main.js
Ext.define("Oreilly.controller.Main",{
extend:'Ext.app.Controller', xtype:'maincontroller', init:function(){ alert('Main控制器的init()方法被調(diào)用'); }, launch:function(){ alert('Main控制器launch()方法被調(diào)用'); }, config:{ } }); ---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
來自: I_T_館 > 《Sencha Touch》