說明: 本教程在我推薦的ajax/ext目錄規範環境下開發,如環境不同,請自行修改相關路徑
本項目架構及代碼在此下載
1.開啟項目
2.在根目錄下建立demo.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>ExtJs Gui Designer Demo</title>
<!-- The ExtJs base 2.02 -->
<link rel="stylesheet" type="text/css" href="framework/ext-2.0.2/resources/css/ext-all.css" temp_href="framework/ext-2.0.2/resources/css/ext-all.css"/>
<script type="text/javascript" src="framework/ext-2.0.2/adapter/ext/ext-base.js" temp_src="framework/ext-2.0.2/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="framework/ext-2.0.2/ext-all.js" temp_src="framework/ext-2.0.2/ext-all.js"></script>
<!-- The Json Panel -->
<script type="text/javascript" src="widget/Ext.ux.JsonPanel.js" temp_src="widget/Ext.ux.JsonPanel.js"></script>
</head>
<body>
<script>
new Ext.Viewport({
items : new Ext.ux.JsonPanel({autoLoad:'modules/user.json'}),
layout: 'fit'
}).show();
</script>
</body>
</html>
注意 其中user.json就是GUIBUILDER中產生的程式碼.
3.開啟GuiBuilder
4.設計介面
1).首先雙擊 FormPanel,或把FormPanel拖進主面板
2)接著拖動TextField進入FormPanle,並修改FieldLabel為"使用者名稱",添加"id"屬性為"username"
3)再插入一個按鈕button,添加handle事件
4)點擊click here to edit,彈出指令碼編輯框,在其實輸入:
function(){
alert(Ext.get("username").getValue());
}
輸入,點擊apply
5) 點擊 copy json,或開啟edit json,拷貝其中的代碼,將其另存新檔user.json
6) 開啟demo.html