【ExtJS】FormPanel 布局(一)

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   io   strong   ar   for   

準備工作,布置一個最簡單的Form,共5個組件,都為textfield。

 1 Ext.onReady(function(){ 2     Ext.create(‘Ext.form.Panel‘, { 3         width: 500, 4         title: ‘Layout‘, 5      renderTo : ‘form‘, 6         items: [{ 7             xtype : ‘textfield‘, 8             fieldLabel : ‘edit1‘, 9             name : ‘edit1‘,10         },{11             xtype : ‘textfield‘,12             fieldLabel : ‘edit2‘,13             name : ‘edit1‘,14         },{15             xtype : ‘textfield‘,16             fieldLabel : ‘edit3‘,17             name : ‘edit1‘,18         },{19             xtype : ‘textfield‘,20             fieldLabel : ‘edit4‘,21             name : ‘edit1‘,22         },{23             xtype : ‘textfield‘,24             fieldLabel : ‘edit5‘,25             name : ‘edit1‘,26         }],27      buttons : [{28        text : ‘upDate‘,29        handler : function(){30          //do something...31        }32      }] 33     });34 })

效果: 

1、Absolute絕對布局:

  使用標準x,y屬性進行x/y座標定位。

 1 Ext.create(‘Ext.form.Panel‘, { 2   title: ‘Absolute‘, 3   renderTo: ‘absolute‘, 4   width: 500, 5   height: 250, 6   layout: ‘absolute‘, 7   items: [{ 8      xtype : ‘textfield‘, 9     fieldLabel : ‘edit1‘,10      width : 100,11      name : ‘edit1‘,12      x : 10,13       y : 1014    },{15      xtype : ‘textfield‘,16      fieldLabel : ‘edit2‘,17      width : 160,18      name : ‘edit1‘,19      x : 20,20      y : 4021    },{22      xtype : ‘textfield‘,23      fieldLabel : ‘edit3‘,24      width : 60,25      name : ‘edit1‘,26       x : 30,27      y : 7028    },{29       xtype : ‘textfield‘,30       fieldLabel : ‘edit4‘,31       width : 190,32        name : ‘edit1‘,33       x : 40,34       y : 10035   },{36     xtype : ‘textfield‘,37     fieldLabel : ‘edit5‘,38     width : 220,39     name : ‘edit1‘,40     x : 50,41     y : 13042   }],43   buttons : [{44     text : ‘upDate‘,45     handler : function() {46           //do something...47     }48   }]   49 });

效果:

ps:在調試的時候遇到一個情況,如果僅設定寬width而不設定高height的話,會出現“Layout run failed ”錯誤。不過若是僅設定高而不設定寬,則Form寬填充整個頁面,而不會出現錯誤。

2、accordion手風琴式布局:

注意:只有 Ext的各種Panel和Ext.panel.Panel的子類可以用於這種布局的容器中.

諸如Header、Table、Tool等,子類有:

  Ext.container.ButtonGroup  Ext.form.Panel  Ext.menu.Menu  Ext.panel.Table  Ext.tab.Panel  Ext.tip.Tip  Ext.window.Window
 1 Ext.create(‘Ext.form.Panel‘, { 2     width: 500, 3     height: 250, 4     title: ‘Accordion‘, 5     renderTo: ‘accordion‘, 6     layout : ‘accordion‘, 7     items: [{ 8         title: ‘Panel1‘, 9         html: ‘Panel content!‘10     },{11         itle: ‘Panel2‘,12         html: ‘Panel content!‘13     },{14         title: ‘Panel3‘,15         html: ‘Panel content!‘16     }],17     buttons : [{18        text : ‘open Panel3‘,19       handler : function() {20           Ext.getCmp(‘Panel3‘).expand(true);21       }22     }]   23 });                    

效果:

3、Anchor式布局:

根據父控制項寬高,以固定百分比或者固定位移量來決定子控制項的尺寸。

 1 Ext.create(‘Ext.form.Panel‘,{ 2     width: 500, 3     height: 400, 4     title: ‘Anchor‘, 5     renderTo: ‘anchor‘, 6     layout: ‘anchor‘, 7     buttonAlign : ‘center‘, 8     items: [{ 9         xtype: ‘panel‘,10           title: ‘75% Width and 20% Height‘,11           anchor: ‘75% 20%‘12         },{13          xtype: ‘panel‘,14           title: ‘Offset -300 Width and -200 Height‘,15             anchor: ‘-300 -200‘     16         },{17             xtype: ‘panel‘,18             title: ‘Offset -200 Width and 40% Height‘,19             anchor: ‘-250 40%‘20         }],21     buttons : [{22         text : ‘upDate‘,23         handler : function() {24             //do something..25         }26     }]  27 });                

效果:

 

4、Auto

 1 Ext.create(‘Ext.form.Panel‘,{ 2     width: 500, 3     height: 400, 4     title: ‘Auto‘, 5     renderTo: ‘auto‘, 6     layout: ‘auto‘, 7     buttonAlign : ‘center‘, 8     margin: ‘50 150 50 50‘, 9     border: true,10     items: [{11          type: ‘panel‘,12          title: ‘AutoLayout1‘,13          margin: ‘10 10 10 10‘,14          border: true,            15     },{16         xtype: ‘panel‘,17     title: ‘AutoLayout2‘,18     border: true,19     margin: ‘10 10 10 10‘20     }],21     buttons : [{22         text : ‘upDate‘,23         handler : function() {24             //do something..25     }26     }]  27 });          

效果:

 

一些常用配置與問題:

1、border 邊框設定

  預設為false,邊框不可見。true為邊框可見。

2、margin 組件頁邊

  margin 可以是一個數值適用於所有邊 或者它可以是每個樣式的CSS樣式規範, 例如: ‘10 5 3 10‘。

3、buttonAlign 按鈕Button位置

  指定Panel中按鈕的位置。可配置的值有‘right‘, ‘left‘ 和 ‘center‘(對於所有的buttons/fbar預設為‘right‘,對於toolbar 則預設為‘left‘)。

4、handler : function(){}

  按鈕點擊事件的觸發。

5、關於標籤fieldLabel與title

  title為要現實的標籤文本。

  fieldLabel為域標籤。它被附加了labelSeparator, 其位置和大小被labelAlign、 labelWidth和labelPad配置確認。

    labelSeparator: 插入到fieldLabel後面的字元。預設為":" 

    labelAlign: 控制fieldLabel的位置和對齊。有效值為:

       "left" (預設) - 標籤位於域的左邊,其文本靠左對齊。其寬度由labelWidth配置確定。

       "top" - 標籤位於域的頂端。

       "right" - 標籤位於域的右邊,其文本靠右對齊。其寬度由labelWidth配置確定。

    labelWidth: fieldLabel以像素為單位的寬度。只適用於 labelAlign設定了“left”或“right”。預設為"100"。

    labelPad: fieldLabel和輸入欄位之間的像素空間的合計。預設為"5"。

 

【ExtJS】FormPanel 布局(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.