富客戶端程序設計實例 - 視圖層(Ext JS) - 頁面與窗口的打開控制
點擊按鈕打開一個窗口,包括Windows窗口和Panel窗體。每次點擊按鈕不能打開多個窗體。設計的原則是打開窗口時,保存這個要打開的組件的ID;當關閉這個窗口的時候,對應在數組中刪除這個組件的ID。這個類是pageHelper.js。代碼如下:
- var list = new Array();
- Ext.define("appUtils.pageHelper" , //類名定義包含文件夾
- {
- // 添加一個組件 ID 到 ArrayList 中
- addComponentID : function(id)
- {
- Ext.Array.push(list , id);
- } ,
- //判斷組件如 window/tab panel 等是否已打開 參數:組件id
- isComponentOpen : function(id)
- {
- var isOpen = Ext.Array.contains(list, id );
- if(isOpen == true){
- return true;
- }
- else{
- return false;
- }
- },
- //移除這個組件Id
- removeComponentID : function(id)
- {
- Ext.Array.remove(list , id) ;
- } ,
- // 控制頁面視圖中間區域被打開的Tab、panel等組件的關閉與開啟 ---控制的控件為Panel及其子類
- panelComponentController : function(compName )
- {
- //根據centerArea組件的ID來獲取這個對象 ,然后調用add方法
- var centerArea = Ext.getCmp("centerTab");
- var openedComp = Ext.create(compName);
- //創建對象與獲取對象不同;創建:對象沒有加載和顯示。獲取:對象已經加載
- if(openedComp.isPanel == true) //方法只用于panel及其子類對象
- {
- if( this.isComponentOpen(openedComp.id) == false )
- {
- centerArea.add(openedComp); //在Viewpoint的中心加入一個新Tab頁
- this.addComponentID(openedComp.id);
- }
- else {
- //數組中包含組件ID,代表組件已經打開
- console.log("The panel has opened");
- }
- }
- else{
- console.log("該方法只用于 panel對象及其子類對象");
- return ;
- }
- } ,
- //控制被打開的Windows組件 --控制條件為windows及其子類組件
- windowComponentController : function(compName)
- {
- var winComp = Ext.create(compName);
- if(winComp.isWindow == true)
- {
- if(this.isComponentOpen(winComp.id) == false)
- {
- winComp.show();
- this.addComponentID(winComp.id)
- }
- else{
- //數組中包含組件ID,代表組件已經打開
- console.log("The window has opened .")
- }
- }
- else{
- console.log("該方法只用于 window 對象及其子類對象");
- return ;
- }
- } ,
- // 控制頁面視圖中間區域被打開的Tab、panel等組件的關閉與開啟 ---Container對象及其子類對象
- containerComponentController : function(compName )
- {
- var centerArea = Ext.getCmp("centerTab");
- var openedComp = Ext.create(compName);
- if(openedComp.isContainer == true) //方法只用于panel及其子類對象
- {
- if( this.isComponentOpen(openedComp.id) == false )
- {
- centerArea.add(openedComp); //在Viewpoint的中心加入一個新Tab頁
- this.addComponentID(openedComp.id);
- }
- else {
- console.log("The panel has opened");
- }
- }
- else{
- console.log("該方法只用于 Container 對象及其子類對象");
- return ;
- }
- }
- }) ; </ol> </div> </div>
- var pt = Ext.create("appUtils.pageHelper");
- Ext.define('Hongbo.view.Viewport',
- { 省略后續代碼 …… </ol> </div> </div>
- Ext.define('Hongbo.view.west.childViews.DaKa_Tabpanel',
- {
- extend:"Ext.tab.Panel",
- alias : 'widget.DaKaTabpanel',
- id:'DaKaTab',
- title: '異動申請 ' ,
- closable: true,
- closeAction:'destroy' ,
- listeners:
- {
- 'close':function()
- {
- pt.removeComponentID("DaKaTab");
- }
- }
- }); </ol> </div> </div>
- {
- xtype:"button",
- text:"CURD",
- width:150,
- height:40,
- handler:function()
- {
- pt.containerComponentController('Hongbo.view.west.childViews.ChaKan_table')
- }
- } </ol> </div> </div>
var pt = Ext.create("appUtils.pageHelper"); 作為全局變量控制。Ext JS中在定義一個類之前引入是作為全局變量來控制,代碼如下:
在對應的打開窗體腳本中添加事件監聽代碼:
在westArea.js中調用某一個窗口的代碼:
本文由用戶 Yangcl 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!
推薦閱讀
富客戶端程序設計實例 - 視圖層(Ext JS) - 頁面與窗口的打開控制
點擊按鈕打開一個窗口,包括Windows窗口和Panel窗體。每次點擊按鈕不能打開多個窗體。設計的原則是打開窗口時,保存這個要打開的組件的ID;當關閉這個窗口的時候,對應在數組中刪除這個組件的I...
富客戶端程序設計實例 - 視圖層(Ext JS) - Ext MVC Application Architecture 簡介
Ext MVC Application Architecture 是ExtJS4.0開始引入的一種全新的開發模式。Ext本身作為一種視圖層存在,但因為其開發復雜性為初學者所詬病。在ExtJS3....
富客戶端程序設計實例 - 視圖層(Ext JS) - 頁面腳本結構
simple.html作為前端頁面的入口,app.js作為javascript腳本的入口點被simple.html所引用。app.js在整個Ext JS MVC中是入口的作用。app.js代碼如...
富客戶端程序設計實例 - 視圖層(Ext JS) - 前后臺數據交互
后臺返回Json串樣式,其中包括了results、items和success3個節點。results是返回的記錄條數,items是記錄的信息,success用于判斷讀取是否成功。 {"resul...