天天看點

Think of Ext2.0

Ext2.0的選擇需要冒很大的風險,确實Ext在界面上能夠有很大的提升,但是用戶端機器的性能和網絡方面的制約,再加上Ext本身沒有很好的實作工具支援。從編碼角度來說,可能需要花費更多的時間,這相對于直接的Web開發。如果項目中缺少美工,又對通路性能或并發量不是特别的要求的Web開發,可以考慮使用,譬如說安全裝置的控制界面。當然項目組成員必須忍受大量javascript編碼。

一般來說,Ext使用如下:

Ext 作為前台,Spring-Hibernate-Stucts作為整體的控制層,json-lib作為兩者的互動。

當然背景是什麼無所謂了,主要就是json字元串的拼湊

流程稍微記錄了一下,後面有些不想寫了,是以邏輯有些混亂。

1. Json-Lib

導入依賴庫

commons-beanutils.jar

commons-collections-3.1.jar

commons-lang-2.1.jar

commons-logging.jar

ezmorph-1.0.4.jar

json-lib-2.2-jdk15.jar

測試Bean類

Think of Ext2.0
Think of Ext2.0

public class TestBean ...{

Think of Ext2.0

String date1 = "111";

Think of Ext2.0

int date2 = 10;

Think of Ext2.0
Think of Ext2.0

public String getDate1() ...{

Think of Ext2.0

return date1;

Think of Ext2.0

}

Think of Ext2.0
Think of Ext2.0

public void setDate1(String date1) ...{

Think of Ext2.0

this.date1 = date1;

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

public int getDate2() ...{

Think of Ext2.0

return date2;

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

public void setDate2(int date2) ...{

Think of Ext2.0

this.date2 = date2;

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

測試代碼

Think of Ext2.0

JSONObject jsonBean = JSONObject.fromObject(new TestBean());

Think of Ext2.0

System.out.println(jsonBean);

Think of Ext2.0
Think of Ext2.0

List list = new ArrayList();

Think of Ext2.0

list.add(new TestBean());

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

JSONArray jsonList = JSONArray.fromObject(list);

Think of Ext2.0

System.out.println(jsonList);

Think of Ext2.0

輸出:

{"date1":"111","date2":10}

[{"date1":"111","date2":10},{"date1":"111","date2":10}]

正式使用再做一下字元串處理

2. Ext使用

将整個Ext2.0的目錄導入到MyEclipse中去

Docs可以全部删去,example 也可删去部分

隻保留examples根目錄下的内容

在examples\examples.js中的開頭修改成

Ext.BLANK_IMAGE_URL = 'ext-2.0/resources/images/default/s.gif';

将指向Ext網站的s.gif檔案指向本地

添加 ext-fix.js 修正radio等Form控件從json資料擷取資訊時,工作不正常的問題

Think of Ext2.0
Think of Ext2.0

Ext.form.BasicForm.prototype.setValues = function(values)...{

Think of Ext2.0
Think of Ext2.0

if(values instanceof Array)...{

Think of Ext2.0
Think of Ext2.0

for(var i = 0, len = values.length; i < len; i++)...{

Think of Ext2.0

var v = values[i];

Think of Ext2.0

var f = this.findField(v.id);

Think of Ext2.0
Think of Ext2.0

if(f)...{

Think of Ext2.0
Think of Ext2.0

if ( f.getEl().dom.type == 'radio' ) ...{

Think of Ext2.0

var group = this.el.dom.elements[f.getName()];

Think of Ext2.0
Think of Ext2.0

for (var i=0; i < group.length; i++ ) ...{

Think of Ext2.0
Think of Ext2.0

if(group[i].__ext_field) ...{

Think of Ext2.0

group[i].__ext_field.setValue(group[i].value == v);

Think of Ext2.0
Think of Ext2.0

if(this.trackResetOnLoad)...{

Think of Ext2.0

group[i].__ext_field.originalValue = group[i].__ext_field.getValue();

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

else

Think of Ext2.0
Think of Ext2.0

...{

Think of Ext2.0

f.setValue(v.value);

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

f.originalValue = f.getValue();

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

}else...{

Think of Ext2.0

var field, id;

Think of Ext2.0
Think of Ext2.0

for(id in values)...{

Think of Ext2.0
Think of Ext2.0

if(typeof values[id] != 'function' && (field = this.findField(id)))...{

Think of Ext2.0
Think of Ext2.0

if( field.getEl().dom.type == 'radio' ) ...{

Think of Ext2.0

var group = this.el.dom.elements[field.getName()];

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

group[i].__ext_field.setValue(group[i].value == values[id]);

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

field.setValue(values[id]);

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

field.originalValue = field.getValue();

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

return this;

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

Ext.form.Radio.prototype.onRender = function(ct, position) ...{

Think of Ext2.0

Ext.form.Radio.superclass.onRender.call(this, ct, position);

Think of Ext2.0

this.el.dom.__ext_field = this;

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

Ext.form.Radio.prototype.setValue = function(v) ...{

Think of Ext2.0
Think of Ext2.0

if(v === true || v === 'true' || v == '1' || v === false || v === 'false' || v == '0') ...{

Think of Ext2.0
Think of Ext2.0

// Select all radios of this group

Think of Ext2.0

var radios = this.el.up('form').select('input[type=radio]');

Think of Ext2.0
Think of Ext2.0

// Uncheck all other values

Think of Ext2.0
Think of Ext2.0

for(var i = 0; i < radios.elements.length; i++) ...{

Think of Ext2.0

if(radios.elements[i].__ext_field && radios.elements[i].__ext_field != this && radios.elements[i].name == this.el.dom.name)

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

radios.elements[i].__ext_field.checked = false;

Think of Ext2.0
Think of Ext2.0

// DOM checked is set by the browser

Think of Ext2.0
Think of Ext2.0

radios.elements[i].__ext_field.fireEvent("check", this, this.checked);

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

this.checked = (v === true || v === 'true' || v == '1');

Think of Ext2.0
Think of Ext2.0

if(this.el && this.el.dom) ...{

Think of Ext2.0

this.el.dom.checked = this.checked;

Think of Ext2.0
Think of Ext2.0

this.fireEvent("check", this, this.checked);

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

在使用Ext項目中将所有的檔案的編碼調到UTF-8,這包括js檔案和頁面檔案。因為Ext核心使用UTF-8編碼,在表單送出和Grid時表現得比較明顯。

使用Ext時,在頁面檔案的<head></head>中加入下面内容

Think of Ext2.0

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

Think of Ext2.0

<title>Forms</title>

Think of Ext2.0

<link rel="stylesheet" type="text/css" href="ext-2.0/resources/css/ext-all.css"/>

Think of Ext2.0
Think of Ext2.0

<!-- GC -->

Think of Ext2.0

<!-- LIBS -->

Think of Ext2.0
Think of Ext2.0

<script type="text/javascript" src="ext-2.0/adapter/ext/ext-base.js"></script>

Think of Ext2.0

<!-- ENDLIBS -->

Think of Ext2.0
Think of Ext2.0

<script type="text/javascript" src="ext-2.0/ext-all.js"></script>

Think of Ext2.0

<script type="text/javascript" src="ext-2.0/build/locale/ext-lang-zh_CN.js"></script>

Think of Ext2.0

<script type="text/javascript" src="ext-2.0/ext-fix.js"></script>

Think of Ext2.0

<!-- Common Styles for the examples -->

Think of Ext2.0

<link rel="stylesheet" type="text/css" href="ext-2.0/examples/examples.css"/>

Think of Ext2.0

<script type="text/javascript" src="ext-2.0/examples/examples.js"></script>

Think of Ext2.0

這一部分可以制作頁面模闆

每個獨立的頁面 再加入自己獨特的js邏輯,以dynamic.js為例

Think of Ext2.0

<script type="text/javascript" src="dynamic.js"></script>

如果頁面需要div的話,就加入即可。

3. Form

表單制作包括送出和資料内容的填充

制作Ext Form表單, 可以使用Ext form builder來簡化一些操作。

Ext Form Builder同樣使用Ext開發

Think of Ext2.0

首先添加一個Form Panel

然後将所需要的Form控件拖到Form Panel上即可

選擇Show/Edit JSON就可以看到生成表單所需要的javascript語句

1) 表單送出

Think of Ext2.0

制作上面的這個表單

兩個Edit,一個Combo和一個Radio,代碼中有些布局資訊也可以使用Form Builder來制作,但是Form Builder不支援%的布局方式,可以手工改寫生成界面的json來達到效果。

表單送出時,使用各個控件name值作為請求參數

這裡的控件都有些布局資訊,可以忽略

l Edit控件

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

columnWidth : .5,

Think of Ext2.0

layout : 'form',

Think of Ext2.0

border : false,

Think of Ext2.0
Think of Ext2.0

items : [...{

Think of Ext2.0

xtype : 'textfield',

Think of Ext2.0

fieldLabel : '姓名',

Think of Ext2.0

name : 'name',

Think of Ext2.0

anchor : '90%'

Think of Ext2.0

}]

Think of Ext2.0

如果需要填寫預設值的話,加入value參數即可

送出時也是使用最新的value值來送出的

l Radio控件

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

columnWidth : .25,

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

style : 'margin-top:5px',

Think of Ext2.0

xtype : 'radio',

Think of Ext2.0

fieldLabel : '性别',

Think of Ext2.0

boxLabel : '男',

Think of Ext2.0

name : 'sex',

Think of Ext2.0

checked : true,

Think of Ext2.0

inputValue : 'M',

Think of Ext2.0

anchor : '95%'

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

}, ...{

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

labelWidth : 0,

Think of Ext2.0

labelSeparator : '',

Think of Ext2.0

hideLabels : true,

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

fieldLabel : '',

Think of Ext2.0

boxLabel : '女',

Think of Ext2.0
Think of Ext2.0

inputValue : 'F',

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

Radio使用inputValue來作為送出值,接收時也使用這個值

l Combo控件

Combo控件擷取資訊的Json字元串格式

Think of Ext2.0
Think of Ext2.0

...{totalProperty:100,root:[...{retrunValue:1, displayText:'中文1'},...{retrunValue:2, displayText:'中文2'},...{retrunValue:3, displayText:'中文3'},...{retrunValue:4, displayText:'中文4'},...{retrunValue:5, displayText:'中文5'},...{retrunValue:6, displayText:'中文6'}]}

這裡使用combo.jsp來傳回這些資訊

Think of Ext2.0

<%@ page language="java" contentType="text/html; charset=UTF-8"

Think of Ext2.0

pageEncoding="UTF-8"%>

Think of Ext2.0

<%

Think of Ext2.0
Think of Ext2.0

response.setCharacterEncoding("UTF-8");

Think of Ext2.0
Think of Ext2.0

String json = "{totalProperty:100,root:[";

Think of Ext2.0
Think of Ext2.0

json += "{retrunValue:1, displayText:'中文1'},"

Think of Ext2.0

+"{retrunValue:2, displayText:'中文2'},"

Think of Ext2.0

+"{retrunValue:3, displayText:'中文3'},"

Think of Ext2.0

+"{retrunValue:4, displayText:'中文4'},"

Think of Ext2.0

+"{retrunValue:5, displayText:'中文5'},"

Think of Ext2.0

+"{retrunValue:6, displayText:'中文6'}]}";

Think of Ext2.0
Think of Ext2.0

response.getWriter().write(json);

Think of Ext2.0
Think of Ext2.0

%>

擷取的資料源

Think of Ext2.0
Think of Ext2.0

var ds = new Ext.data.Store(...{

Think of Ext2.0
Think of Ext2.0

proxy: new Ext.data.HttpProxy(...{url:'combo.jsp'}),

Think of Ext2.0
Think of Ext2.0

reader: new Ext.data.JsonReader(...{

Think of Ext2.0

totalProperty: 'totalProperty',

Think of Ext2.0

root: 'root'

Think of Ext2.0

}, [

Think of Ext2.0
Think of Ext2.0

...{name: 'retrunValue', type: 'int'},

Think of Ext2.0
Think of Ext2.0

...{name: 'displayText'}

Think of Ext2.0

])

Think of Ext2.0
Think of Ext2.0

});

Think of Ext2.0

'totalProperty' json中記錄的總數量

'root' json中資料開頭的标示

'retrunValue' 和'displayText' 為資料對象的字段名稱, 其中'retrunValue'為int類型

從combo.jsp中擷取json資料将組裝成定義資料源類型

Combo使用這個資料源

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

xtype:'combo',

Think of Ext2.0

store: ds,

Think of Ext2.0

valueField :"retrunValue",

Think of Ext2.0

displayField: "displayText",

Think of Ext2.0

mode: 'local',

Think of Ext2.0

forceSelection: true,

Think of Ext2.0

blankText:'請選擇學曆',

Think of Ext2.0

emptyText:'選擇學曆',

Think of Ext2.0

hiddenName:'education',

Think of Ext2.0

editable: false,

Think of Ext2.0

triggerAction: 'all',

Think of Ext2.0

allowBlank:false,

Think of Ext2.0

fieldLabel: '學曆',

Think of Ext2.0

name: 'education',

Think of Ext2.0

anchor:'90%'

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

Combo的值為"retrunValue",顯示使用"displayText"

當然最後不要忘記将ds進行load

l 儲存按鈕将表單資訊進行送出

Think of Ext2.0
Think of Ext2.0

buttons : [ ...{

Think of Ext2.0

text : '儲存',

Think of Ext2.0
Think of Ext2.0

handler : function() ...{

Think of Ext2.0
Think of Ext2.0

if (simpleForm.form.isValid()) ...{

Think of Ext2.0

this.disabled = true;

Think of Ext2.0
Think of Ext2.0

simpleForm.form.doAction('submit', ...{

Think of Ext2.0

url : 'test.jsp',

Think of Ext2.0

method : 'post',

Think of Ext2.0

params : '',

Think of Ext2.0
Think of Ext2.0

success : function(form, action) ...{

Think of Ext2.0

Ext.Msg.alert('成功', action.result.data);

Think of Ext2.0

this.disabled = false;

Think of Ext2.0

//document.location.href = 'hello.html';

Think of Ext2.0

},

Think of Ext2.0
Think of Ext2.0

failure : function() ...{

Think of Ext2.0

Ext.Msg.alert('失敗', '抱歉');

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

儲存按鈕将表單資訊送出給test.jsp,我們将所有的請求參數列印出來,并傳回結果資訊

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

request.setCharacterEncoding("UTF-8");

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

try...{

Think of Ext2.0

String name;

Think of Ext2.0

java.util.Enumeration pNames=request.getParameterNames();

Think of Ext2.0
Think of Ext2.0

while(pNames.hasMoreElements())...{

Think of Ext2.0

name=(String)pNames.nextElement();

Think of Ext2.0

System.out.println(name+"="+request.getParameter(name));

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

}catch(Exception e)...{

Think of Ext2.0

System.out.print(e.toString());

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

out.print("{success:true, data:age=567}");

Think of Ext2.0
Think of Ext2.0

列印處來的例子

age=dfgg

name=ddfgdfg

sex=M

education=3

傳回參數也必須是json字元串,success表示操作成功,或失敗

action.result.data會取=後的值

Think of Ext2.0

2) 表單接收資訊

隻需要傳回和表單相符的JSON字元串

{success:true,data:{"name":'你好',"age":'131',education:3,sex:'F'}}

formget.jsp檔案内容

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

out.print("{success:true,data:{"name":'你好',"age":'131',education:3,sex:'F'}}");

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

取消按鈕從formget.jsp中擷取這個字元串資訊,來填充表單

Think of Ext2.0

buttons : [

Think of Ext2.0

...

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

text : '取消',

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

simpleForm.form.load( ...{

Think of Ext2.0

url : 'formget.jsp',

Think of Ext2.0

method : 'get',

Think of Ext2.0

params : ''

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

當然也可以在開始時,就調用來導入資料

4. Grid

Think of Ext2.0

Grid所需要的json字元串

{totalProperty:100,root:[{id:1,name:'二月DD1',descn:'descn1'},{id:2,name:'二月DD2',descn:'descn2'},{id:3,name:'二月DD3',descn:'descn3'},{id:4,name:'二月DD4',descn:'descn4'},{id:5,name:'二月DD5',descn:'descn5'},{id:6,name:'二月DD6',descn:'descn6'},{id:7,name:'二月DD7',descn:'descn7'},{id:8,name:'二月DD8',descn:'descn8'},{id:9,name:'二月DD9',descn:'descn9'},{id:10,name:'二月DD10',descn:'descn10'}]}

Grid.jsp 根據起始值和限制數量決定傳回json字元串

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

//response.setCharacterEncoding("UTF-8");

Think of Ext2.0

String start = request.getParameter("start");

Think of Ext2.0

String limit = request.getParameter("limit");

Think of Ext2.0
Think of Ext2.0

try ...{

Think of Ext2.0

int index = Integer.parseInt(start);

Think of Ext2.0

int pageSize = Integer.parseInt(limit);

Think of Ext2.0
Think of Ext2.0

//String json = "{totalProperty:100,root:[";

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

for (int i = index; i < pageSize + index; i++) ...{

Think of Ext2.0

json += "{id:" + i + ",name:'二月DD" + i + "',descn:'descn" + i + "'}";

Think of Ext2.0
Think of Ext2.0

if (i != pageSize + index - 1) ...{

Think of Ext2.0

json += ",";

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

json += "]}";

Think of Ext2.0
Think of Ext2.0

//out.print(json);

Think of Ext2.0
Think of Ext2.0

} catch(Exception ex) ...{

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

擷取資料時,如此通路grid.jsp檔案

grid.jsp?start=1&limit=10

Grid使用

Grid中字段定制

Think of Ext2.0

var cm = new Ext.grid.ColumnModel([

Think of Ext2.0
Think of Ext2.0

...{header:'描述',dataIndex:'id'},

Think of Ext2.0
Think of Ext2.0

...{header:'姓名',width:100, sortable:true,dataIndex:'name'},

Think of Ext2.0
Think of Ext2.0

...{header:'描述',dataIndex:'descn'}

Think of Ext2.0

]);

Think of Ext2.0

Header 顯示名稱

dataIndex 從ds查找字段

width 字段寬度

sortable 是否允許排序

Grid中使用資料源的定義,從grid.jsp中擷取資料

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

proxy: new Ext.data.HttpProxy(...{url:'grid.jsp'}),

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

...{name: 'id'},

Think of Ext2.0
Think of Ext2.0

...{name: 'name'},

Think of Ext2.0
Think of Ext2.0

...{name: 'descn'}

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

定義GridPanel建立Grid

Think of Ext2.0
Think of Ext2.0

var grid = new Ext.grid.GridPanel(...{

Think of Ext2.0

el: 'grid',

Think of Ext2.0

width:600,

Think of Ext2.0

ds: ds,

Think of Ext2.0

cm: cm,

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

bbar: new Ext.PagingToolbar(...{

Think of Ext2.0

pageSize: 10,

Think of Ext2.0
Think of Ext2.0

displayInfo: true,

Think of Ext2.0

displayMsg: '顯示第 {0} 條到 {1} 條記錄,一共 {2} 條',

Think of Ext2.0

emptyMsg: "你好"

Think of Ext2.0

})

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

grid.render();

Think of Ext2.0

el為grid.html中id為grid的div塊

ds 資料源

cm grid顯示列定義

bbar bottom toolbal下面的工具欄

這裡使用分頁控件

最後ds導入時候,使用參數進行過濾

ds.load({params:{start:0,limit:10}});

擴充一下,将上面的Form放入到grid中來

在Grid上添加一個工具欄,通過單擊工具欄中Add Something按鈕,彈出上面的Form資訊

Think of Ext2.0

修改如下:

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

tbar:[...{

Think of Ext2.0

text:'Add Something',

Think of Ext2.0

tooltip:'Add a new row',

Think of Ext2.0

iconCls:'add',

Think of Ext2.0

handler : onItemClick

Think of Ext2.0
Think of Ext2.0

}, '-', ...{

Think of Ext2.0

text:'Options',

Think of Ext2.0

tooltip:'Blah blah blah blaht',

Think of Ext2.0

iconCls:'option'

Think of Ext2.0
Think of Ext2.0

},'-',...{

Think of Ext2.0

text:'Remove Something',

Think of Ext2.0

tooltip:'Remove the selected item',

Think of Ext2.0

iconCls:'remove'

Think of Ext2.0

}],

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

在GridPanel添加在Grid上的Toolbar,Toolbar上添加三個按鈕,并為Add Something添加單擊事件onItemClick。

單擊事件

Think of Ext2.0

var win;

Think of Ext2.0
Think of Ext2.0

function onItemClick(item) ...{

Think of Ext2.0

//alert(item.text);

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

if (!win) ...{

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

var simpleForm = new Ext.FormPanel( ...{

Think of Ext2.0

el : 'hello-tabs',

Think of Ext2.0

labelAlign : 'left',

Think of Ext2.0

title : '你好',

Think of Ext2.0

buttonAlign : 'right',

Think of Ext2.0

bodyStyle : 'padding:5px',

Think of Ext2.0

width : 600,

Think of Ext2.0

frame : true,

Think of Ext2.0

labelWidth : 80,

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

xtype : "textfield",

Think of Ext2.0

fieldLabel : "Text",

Think of Ext2.0

name : "textvalue"

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

layout : 'column',

Think of Ext2.0
Think of Ext2.0

labelSeparator : ':',

Think of Ext2.0
Think of Ext2.0

items : [ ...{

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

fieldLabel : '年齡',

Think of Ext2.0

name : 'age',

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

xtype : 'combo',

Think of Ext2.0

store : ds,

Think of Ext2.0

valueField : "retrunValue",

Think of Ext2.0

displayField : "displayText",

Think of Ext2.0

mode : 'local',

Think of Ext2.0

forceSelection : true,

Think of Ext2.0

blankText : '請選擇學曆',

Think of Ext2.0

emptyText : '選擇學曆',

Think of Ext2.0

hiddenName : 'education',

Think of Ext2.0

editable : false,

Think of Ext2.0

triggerAction : 'all',

Think of Ext2.0

allowBlank : false,

Think of Ext2.0

fieldLabel : '學曆',

Think of Ext2.0

name : 'education',

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

]

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

win = new Ext.Window( ...{

Think of Ext2.0

el : 'hello-win',

Think of Ext2.0

layout : 'fit',

Think of Ext2.0

width : 500,

Think of Ext2.0

height : 300,

Think of Ext2.0

closeAction : 'hide',

Think of Ext2.0

plain : true,

Think of Ext2.0
Think of Ext2.0

items :

Think of Ext2.0

simpleForm,

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

ds.load();

Think of Ext2.0
Think of Ext2.0

win.show(this);

Think of Ext2.0
Think of Ext2.0

唯一需要注意的是儲存和取消按鈕需要加入Ext.Window做控制,并且要注意FormPanel和Ext.Windows所要渲染的div塊,并且這些塊必須在grid.html中進行定義

Think of Ext2.0

<div id="hello-win" class="x-hidden">

Think of Ext2.0

<div class="x-window-header">Hello Dialog</div>

Think of Ext2.0

<div id="hello-tabs">

Think of Ext2.0

<!-- Auto create tab 1 -->

Think of Ext2.0

<div class="x-tab" title="Hello World 1">

Think of Ext2.0

<p>Hello...</p>

Think of Ext2.0

</div>

Think of Ext2.0

<!-- Auto create tab 2 -->

Think of Ext2.0

<div class="x-tab" title="Hello World 2">

Think of Ext2.0

<p>... World!</p>

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

5. Tree

Think of Ext2.0

直接使用Ext例子

Tree所需要的json字元串

[{id:300,text:'01',cls:'task-folder',children:[{id:'2',text:'01-01',leaf:true, cls:'task'},{id:'3',text:'01-02',children:[{id:'4',text:'01-02-01',leaf:true},{id:'5',text:'01-02-02',leaf:true}]},{id:'6',text:'01-03',leaf:true}]},{id:'7',text:'02',leaf:true}]

text"-->顯示的文本

"id"-->id值 ,單擊事件時可以使用

"leaf"-->Boolean值,如果"葉子"是真的話,則不能包含子節點Children nodes

"cls"-->選用的樣式,通常在這裡標明圖示

"href"-->指定的url,還有一個"hrefTarget"的屬性

children -〉表示子節點資訊

在Record.css中自定了兩個定義的css,task和task-folder

.task .x-tree-node-icon {

background-image:url(icons/cog.png) ;

.task-folder .x-tree-node-icon{

background-image:url(icons/folder_go.png) !important;

Json字元串中就使用了這個值

Tree使用如下,相對比較簡單

Think of Ext2.0

var Tree = Ext.tree;

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

var tree = new Tree.TreePanel(...{

Think of Ext2.0

el:'tree-div',

Think of Ext2.0

autoScroll:true,

Think of Ext2.0

animate:true,

Think of Ext2.0

enableDD:true,

Think of Ext2.0

containerScroll: true,

Think of Ext2.0
Think of Ext2.0

loader: new Tree.TreeLoader(...{

Think of Ext2.0

dataUrl:'record.jsp'

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

// set the root node

Think of Ext2.0
Think of Ext2.0

var root = new Tree.AsyncTreeNode(...{

Think of Ext2.0

text: 'Ext JS',

Think of Ext2.0

draggable:false,

Think of Ext2.0

id:'source'

Think of Ext2.0
Think of Ext2.0

tree.setRootNode(root);

Think of Ext2.0
Think of Ext2.0

// render the tree

Think of Ext2.0

tree.render();

Think of Ext2.0

root.expand();

Think of Ext2.0

6. Layout

Think of Ext2.0

左邊為樹型控件,右邊為TabPanel,顯示的頁面

當左邊樹型控件被點選後,右邊的所有的Tab進行變化,通路與樹型清單id相對應的頁面内容

l 布局使用

布局一般使用Viewport

var viewport = new Ext.Viewport({

隻要注意region和el即可

region:'north',

el:'north-div',

el和contentEl的差別

el是第一層div, contentEl一般指向更内部的div

l Tab使用

普通的Tab通路未有無法顯示js的問題

{

title: 'Ajax Tab 1',

autoLoad:{url:'grid.html',scripts:true}

是以就使用了Ext論壇中提供的一個Iframe的擴充 Ext.ux.ManagedIFrame

使用時将miframe.js檔案導入即可

Think of Ext2.0
Think of Ext2.0

var tabs2 = new Ext.TabPanel( ...{

Think of Ext2.0

// renderTo: document.body,

Think of Ext2.0

region : 'center',

Think of Ext2.0

el : 'center-center', // 大的

Think of Ext2.0

//contentEl : 'center-center', // 小的

Think of Ext2.0

activeTab : 0,

Think of Ext2.0
Think of Ext2.0

height : 250,

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

defaults : ...{

Think of Ext2.0

autoScroll : true

Think of Ext2.0
Think of Ext2.0

items : [

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

xtype : "panel",

Think of Ext2.0

title : "Personal Assistant",

Think of Ext2.0
Think of Ext2.0

body : new Ext.ux.ManagedIFrame( ...{

Think of Ext2.0
Think of Ext2.0

autoCreate : ...{

Think of Ext2.0

id:'person', // 設定通路的名稱

Think of Ext2.0

src : 'dynamic.html',

Think of Ext2.0

frameBorder : 0,

Think of Ext2.0

cls : 'x-panel-body',

Think of Ext2.0

width : '100%',

Think of Ext2.0

height : '100%'

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

title : "Personal",

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

id:'person2', // 設定通路的名稱

Think of Ext2.0

src : 'grid.html',

Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0
Think of Ext2.0

l 樹型控件

要給樹型控件添加單擊事件

Think of Ext2.0
Think of Ext2.0

tree.on('click', function(node) ...{

Think of Ext2.0

// do something

Think of Ext2.0

alert(node.id + ' was activated.');

Think of Ext2.0

Ext.get('person').dom.src = 'grid.html?selectedid='+node.id;

Think of Ext2.0
Think of Ext2.0

單擊後,通過查找ManagedIFrame形成的Tab頁的id,并且将其屬性src改變來達到Tab頁内容改變的效果

Think of Ext2.0

參考:

Ext2_0 form使用執行個體 - 天曉得的專欄 - CSDNBlog

Ext 2_0布局執行個體

[2_0][SOLVED] Best practices for getting - saving form data - Ext JS Forums

[EXT Develop Log]--comboBoxradioFix it! - kkbear - JavaEye技術網站

ext學習-tree元件-線上閱讀-新書城

對《Ext2_0 form使用執行個體》的一點補充 - 天曉得的專欄 - CSDNBlog

用Ext 2_0 combobox 做的省份和城市關聯選擇框 - 天曉得的專欄 - CSDNBlog

關于ext和struts的互動 - Allen_CD_China - JavaEye技術網站

從Java 類産生json(json-lib) - windfree - BlogJava

學習EXT第XX天

流氓臨遠, 沒人性洋芋's ext tutorial

And Others, I can't remember

繼續閱讀