ExtJs2.0学习系列--Ext.Panel
生活随笔
收集整理的這篇文章主要介紹了
ExtJs2.0学习系列--Ext.Panel
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ExtJs2.0學習系列--Ext.Panel 2008-06-29 12:59
| 上一篇文章ExtJs2.0學習系列(1)--Ext.MessageBox ,受到了大家的褒貶不一,還是有的朋友提出好的建議,在此表示感謝! 今天介紹extjs中的Panel組件。 //html代碼<div id="container"> ????</div> //js代碼 var p = new Ext.Panel({ ???????? title: 'My Panel',//標題 ???????? collapsible:true,//右上角上的那個收縮按鈕,設為false則不顯示 ???????? renderTo: 'container',//這個panel顯示在html中id為container的層中 ???????? width:400, ???????? height:200, ???????? html: "<p>我是內容,我包含的html可以被執行!</p>"//panel主體中的內容,可以執行html代碼 ???? }); 因為panel組件的子類組件包括TabPanel,GridPanel,FormPanel,TreePanel組件,所以非常有必要介紹Panel組件的配置參數和相關的屬性、方法。 //配置參數(只列舉部分常用參數) 1.autoLoad:有效的url字符串,把那個url中的body中的數據加載顯示,但是可能沒有樣式和js控制,只是html數據 2.autoScroll:設為true則內容溢出的時候產生滾動條,默認為false 3.autoShow:設為true顯示設為"x-hidden"的元素,很有必要,默認為false 4.bbar:底部條,顯示在主體內,//代碼:bbar:[{text:'底部工具欄bottomToolbar'}], 5.tbar:頂部條,顯示在主體內,//代碼:tbar:[{text:'頂部工具欄topToolbar'}], 6.buttons:按鈕集合,自動添加到footer中(footer參數,顯示在主體外)//代碼:buttons:[{text:"按鈕位于footer"}] 7.buttonAlign:footer中按鈕的位置,枚舉值為:"left","right","center",默認為right 8.collapsible:設為true,顯示右上角的收縮按鈕,默認為false 9.draggable:true則可拖動,但需要你提供操作過程,默認為false 10.html:主體的內容 11.id:id值,通過id可以找到這個組件,建議一般加上這個id值 12.width:寬度 13.height:高度 13.title:標題 14.titleCollapse:設為true,則點擊標題欄的任何地方都能收縮,默認為false. 15.applyTo:(id)呈現在哪個html元素里面 16.contentEl:(id)呈現哪個html元素里面,把el內的內容呈現 17.renderTo:(id)呈現在哪個html元素里面 //關于這三個參數的區別(個人認為:applyTo和RenderTo強調to到html元素中,contentEl則是html元素到ext組件中去): 英文如下(本人英語poor,不敢亂翻譯): contentEl - This config option is used to take existing content and place it in the body of a new panel. It is not going to be the actual panel itself. (It will actually copy the innerHTML of the el and use it for the body). You should add either the x-hidden or the x-hide-display CSS class to prevent a brief flicker of the content before it is rendered to the panel. applyTo - This config option allows you to use pre-defined markup to create an entire Panel. By entire, I mean you can include the header, tbar, body, footer, etc. These elements must be in the correct order/hierarchy. Any components which are not found and need to be created will be autogenerated. renderTo - This config option allows you to render a Panel as its created. This would be the same as saying myPanel.render(ELEMENT_TO_RENDER_TO); 哪位大人幫忙翻譯下... 考慮到入門,方法事件會在以后的文章中以實例穿插。 1.可拖動的panel實例 下面我們做個可拖動panel例子來熟悉下panel這個最基本的組件. //html代碼 ..無.. //下面創建一個允許拖動的panel,但是拖動的結果不能保存 var p=new Ext.Panel({ ???? title: 'Drag me', ???? x: 100, ???? y: 100, ???? renderTo: Ext.getBody(),//x,y,renderTo:Ext.getBody()初始化panel的位置 ???? floating: true,//true ???? frame: true,//圓角邊框 ???? width: 400, ???? height: 200, ???? draggable:true }).show();//在這里也可以不show() 但是還不能拖到其他的地方,我們需要改寫draggable: draggable: { ???????? insertProxy: false,//拖動時不虛線顯示原始位置 ???????? onDrag : function(e){ ????????????var pel = this.proxy.getEl(); ????????????this.x = pel.getLeft(true); ????????????this.y = pel.getTop(true);//獲取拖動時panel的坐標 ???????? }, ???????? endDrag : function(e){ ????????????this.panel.setPosition(this.x, this.y);//移動到最終位置 ???????? } ???? } 實現了可保存的拖動,如圖: 拖動的時候陰影還在原位置,我們再在draggable中的onDrag事件中添加代碼: var s = this.panel.getEl().shadow; ????????????if (s) { ???????????????? s.realign(this.x, this.y, pel.getWidth(), pel.getHeight()); ???????????? } //shadow的realign方法的四個參數,改變shadow的位置大小屬性 最后這個可拖動的panel的代碼為: var p=new Ext.Panel({ ???? title: 'Drag me', ???? x: 100, ???? y: 100, ???? renderTo: Ext.getBody(), ???? floating: true, ???? frame: true, ???? width: 400, ???? height: 200, ???? draggable: { ???????? insertProxy: false, ???????? onDrag : function(e){ ????????????var pel = this.proxy.getEl(); ????????????this.x = pel.getLeft(true); ????????????this.y = pel.getTop(true); ????????????var s = this.panel.getEl().shadow; ????????????if (s) { ???????????????? s.realign(this.x, this.y, pel.getWidth(), pel.getHeight()); ???????????? } ???????? }, ???????? endDrag : function(e){ ????????????this.panel.setPosition(this.x, this.y); ???????? } ???? } }) //效果圖片我就不貼出來了 2.帶頂部,底部,腳部工具欄的panel var p=new Ext.Panel({ ??? id:"panel1", ???????? title:"標題", ???????? collapsible:true, ???????? renderTo:"container", ???????? closable:true, ???????? width:400, ???????? height:300, ???????? tbar:[{text:"按鈕1"},{text:"按鈕2"}], //頂部工具欄 ???????? bbar:[{text:"按鈕1"},{text:"按鈕2"}],??//底部工具欄 ???????? html:"內容", ???????? buttons:[{text:"按鈕1"},{text:"按鈕2"}] //footer部工具欄 ??? }); 我們已經在各種工具欄上添加了按鈕,但是卻沒有激發事件,下面我們來添加按鈕事件代碼: tbar:[{text:"按鈕1",handler:function(){Ext.MessageBox.alert("我是按鈕1","我是通過按鈕1激發出來的彈出框!")}},{text:"按鈕2"}], //改寫tbar,添加handler句柄,點擊頂部工具欄上按鈕1,彈出提示框,效果圖大家想象下,就不貼出來了 當然,一般情況下,我們只要一個工具欄,這里只是為了演示! 3.panel工具欄 //添加下面的代碼到panel配置參數中 tools:[{id:"save"},{id:"help"},{id:"up"},{id:"close",handler:function(){Ext.MessageBox.alert("工具欄按鈕","工具欄上的關閉按鈕時間被激發了")}}], //id控制按鈕,handler控制相應的事件 //id的枚舉值為: toggle (collapsable為true時的默認值) close minimize maximize restore gear pin unpin right left up down refresh minus plus help search save 關于panel今天就討論到這里,歡迎批評!一起期待下一片文章. |
轉載于:https://www.cnblogs.com/linpengfeixgu/articles/1298748.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的ExtJs2.0学习系列--Ext.Panel的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CSS实战经验:灵活运行注释带来的益处(
- 下一篇: JS调用后台方法