FormPanel有两种布局:form和column,form是纵向布局,column为横向布局。默认为后者。使用layout属性定义布局类型。对于一个复杂的布局表单,最重要的是正确分割,分割结果直接决定布局能否顺利实现。
如果不再使用默认布局,那么我们必须为每一个元素指定一种布局方式,另外,还必须遵循以下几点:
【1】落实到任何一个表单组件后,最后总是form布局
【2】defaultType属性不一定起作用,必须显式为每一个表单组件指定xtype或new出新对象
【3】在column布局中,通过columnWidth可以指定列所占宽度的百分比,如占50%宽度为.5。

剖析出一个合理的结构,像下面这样 

我们发现,布局其实是由行和列组件成,分成由左往右和由上往下两个方向,由左往右
叫column,由上往下叫form。 
整个大的表单是form布局,从上往下放置了五个小布局,在这里我以行n标记,我们
以行1为例进行分析。行1从左往右有三个表单组件,所以是column布局,行1我们用结
构这样定义: 

layout: “column”, 
items:[{},{},{}] //items表示指定布局内的表单组件集合,在此有三个 
}

行1内其实还有三个form布局,因为每个布局中只有一个表单组件,所以看起来并不
那么明显,我们完全可以放置多个表单组件到布局中。每一个布局使用下面的结构定义: 

layout: “form”, 
items:[{}] //只有一个表单组件 
}

上面的两个结构最终要组装到一起: 

layout: “column”, 
items:[{ 
   layout: “form”, 
   items:[{}] 
},{ 
   layout: “form”, 
   items: [{}] 
},{ 
   layout: “form”, 
   items: [{}] 
}] 
}

实现上面的完整代码是:

Ext.onReady(function() {
    var form = new Ext.form.FormPanel({
       title : "灵活布局的表单",
       width : 650,
       autoHeight : true,
       frame : true,
       renderTo : "a",
       layout : "form", // 整个大的表单是form布局
       labelWidth : 65,
       labelAlign : "right",

items : [{ // 行1
        layout : "column", // 从左往右的布局
        items : [{
           columnWidth : .3, // 该列有整行中所占百分比
           layout : "form", // 从上往下的布局
           items : [{
              xtype : "textfield",
              fieldLabel : "姓",
              width : 120
             }]
          }, {
           columnWidth : .3,
           layout : "form",
           items : [{
              xtype : "textfield",
              fieldLabel : "名",
              width : 120
             }]
          }, {
           columnWidth : .3,
           layout : "form",
           items : [{
              xtype : "textfield",
              fieldLabel : "英文名",
              width : 120
             }]
          }]
       }, { // 行2
          layout : "column",
          items : [{
             columnWidth : .5,
             layout : "form",
             items : [{
                xtype : "textfield",
                fieldLabel : "座右铭1",
                width : 220
               }]
            }, {
             columnWidth : .5,
             layout : "form",
             items : [{
                xtype : "textfield",
                fieldLabel : "座右铭2",
                width : 220
               }]
            }]
         }, {// 行3
          layout : "form",
          items : [{
             xtype : "textfield",
             fieldLabel : "奖励",
             width : 500
            }, {
             xtype : "textfield",
             fieldLabel : "处罚",
             width : 500
            }]
         }, {// 行4
          layout : "column",
          items : [{
             layout : "form",
             columnWidth : 0.2,
             items : [{
                xtype : "textfield",
                fieldLabel : "电影最爱",
                width : 50
               }]
            }, {
             layout : "form",
             columnWidth : 0.2,
             items : [{
                xtype : "textfield",
                fieldLabel : "音乐最爱",
                width : 50
               }]
            }, {
             layout : "form",
             columnWidth : 0.2,
             items : [{
                xtype : "textfield",
                fieldLabel : "明星最爱",
                width : 50
               }]
            }, {
             layout : "form",
             columnWidth : 0.2,
             items : [{
                xtype : "textfield",
                fieldLabel : "运动最爱",
                width : 50
               }]
            }]
         }, {// 行5
          layout : "form",
          items : [{
             xtype : "htmleditor",
             fieldLabel : "获奖文章",
             enableLists : false,
             enableSourceEdit : false,
             height : 150
            }]
         }],
       buttonAlign : "center",
       buttons : [{
          text : "提交"
         }, {
          text : "重置"
         }]
      });
   });

ExtJs FormPanel布局的更多相关文章

  1. Extjs关于FormPanel布局

    Extjs关于FormPanel布局 FormPanel有两种布局:form和column,form是纵向布局,column为横向布局.默认为后者.使用layout属性定义布局类型.对于一个复杂的布局 ...

  2. ExtJs常用布局--layout详解(含实例)

    序言: 笔者用的ExtJs版本:ext-3.2.0 ExtJs常见的布局方式有:border.form.absolute.column.accordion.table.fit.card.anchor ...

  3. 【ExtJS】FormPanel 布局(二)

    周末2天好好学习了下布局,现在都给实现了吧. 5.border布局: Border布局将容器分为五个区域:north.south.east.west和center.除了center区域外,其他区域都需 ...

  4. 【ExtJS】FormPanel 布局(一)

    准备工作,布置一个最简单的Form,共5个组件,都为textfield. Ext.onReady(function(){ Ext.create('Ext.form.Panel', { width: 5 ...

  5. Extjs Column布局常见问题及解决方法

    原文地址:http://blog.csdn.net/weoln/article/details/4339533 第一次用Extjs的column布局时遇见了很多问题,记录下来,供大家参考.column ...

  6. Extjs.FormPanel

    刚刚学习ExtJS ,备注一哈代码 防止忘记... <html xmlns="http://www.w3.org/1999/xhtml"> <head runat ...

  7. Extjs Vbox布局方式,以及align种类,flex,pack属性含义简介

    VBox布局方式,熟悉下一下几个主要属性: 一.align:字符类型,指示组件在容器内的对齐方式.这个是基于容器的左上角来排列的.pack不同,pack是根据容器的最上边来显示的. 1.left(默认 ...

  8. 【ExtJS】 布局Layout

    布局用于定义容器如何组织内部子元素和控制子元素的大小. ExtJS中有两种类型的布局:Container容器类布局与Component组件类布局. Containter容器类布局:负责容器内容Extj ...

  9. formpanel布局的学习

    FormPanel有两种布局:form和column,form是纵向布局,column为横向布局.默认为后者.使用layout属性定义布局类型.对于一个复杂的布局表单,最重要的是正确分割,分割结果直接 ...

随机推荐

  1. TextView及其子类

    1.TextView控件(TextView是EditView.Button等类的父类) <1>android:id   给当前控件定义了一个唯一标识符 <2>android:l ...

  2. [算法 笔记]2014年去哪儿网 开发笔试(续)第一题BUG修正

    上一篇的blog地址为:http://www.cnblogs.com/life91/p/3313868.html 这几天又参加了一个家公司的笔试题,在最后的编程题中竟然出现了去哪儿网开发的第一题,也就 ...

  3. android开发软件

    android开发软件: http://developer.android.com/sdk/index.html#download

  4. sed命令使用记录

    背景:文件A,文件B,文件格式一致,有两列,第一列为key,第二列为value. 目的:将文件A中的内容插入到文件B中,不能在最后,不能有重复key(我的key和value用tab键分割) 实现:我的 ...

  5. 【转】linux打包压缩命令

    转自:http://www.cnblogs.com/end/archive/2011/04/20/2022614.html tar命令 [root@linux ~]# tar [-cxtzjvfpPN ...

  6. EventSource (node.js 与 OC)

    node.js服务器代码: var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, ...

  7. 轻松学习Linux之入门篇

    1.Linux概述: 2.Linux优点 3.linux历史待上传 4.linux部分发行版 5.linux政府扶持 本文出自 "李晨光原创技术博客" 博客,谢绝转载!

  8. EntityFramwork6连接MySql错误

    EntityFramwork6连接MySql错误 使用EF6连接MySql产生Exception: ProHub.ssdl(2,2) : 错误 0152: MySql.Data.MySqlClient ...

  9. NetBeans平台中调用状态栏

    http://blog.csdn.net/mycsoft/article/details/2326386 StatusDisplayer stD = StatusDisplayer.getDefaul ...

  10. Java Applet and ServiceLoader

    http://stackoverflow.com/questions/14062813/java-applet-and-serviceloader