日期:2014-05-16  浏览次数:20333 次

ExtJS小知识【多处收集供自己参考】
Ext.get(document.body).update('<div id="test"></div>');


基本页面:
- index.html
		<html>
		<head>
		    <title>Hello Ext</title>
		
		    <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css">
		    <script type="text/javascript" src="extjs/ext-debug.js"></script>
		    <script type="text/javascript" src="app.js"></script>
		</head>
		<body></body>
		</html>


- index-prod.html

<html>
		<head>
		    <title>Hello Ext</title>
		
		    <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css">
		    <script type="text/javascript" src="extjs/ext.js"></script>
		    <script type="text/javascript" src="app-all.js"></script>
		</head>
		<body></body>
		</html>


部署(自定义生成只包含应用程序需要的代码):
1.运行-cmd-cd命令浏览到应用程序所在的目录
2.生成JSB3文件(可省略)
sencha create jsb -a index.html -p app.jsb3

3.
sencha create jsb -a http://localhost/helloext/index.html -p app.jsb3

4.
sencha build -p app.jsb3 -d .




一、ExtJS的form表单的提交:
1.ajax(默认提交)

handler: function(){
	        		if (!formPanel.getForm().isValid()) return;
	        		formPanel.getForm().submit({
			           waitMsg: '正在提交數據',
			           waitTitle: '提示',
			           method:'POST',
			           url: '',
			           success: function(form, action) {
			               Ext.Msg.alert('提示', '提交成功');
			           },
			           failure: function(form, action) {
			               Ext.Msg.alert('提示', '錯誤,原因如下:' + action.result.errors.info);
			           }
       			  });
	        	}

2.非ajax提交

//实现非AJAX提交表单一定要加下面的两行!
onSubmit : Ext.emptyFn, 
submit : function() {
	//再次设定action的地址
	this.getEl().dom.action ='user.do?method=login'; this.getEl().dom.method = 'post';
	//提交submit
	this.getEl().dom.submit();
};



3.ajax提交

Ext.Ajax.request({
 	 //请求地址
	 url: 'login.do',
   //提交参数组
   params: {
   		LoginName:Ext.get('LoginName').dom.value,
   		LoginPassword:Ext.get('LoginPassword').dom.value
   },
   //成功时回调
   success: function(response, options) {
	   //获取响应的json字符串
	   var responseArray = Ext.util.JSON.decode(response.responseText);
	   if(responseArray.success==true){
	   		Ext.Msg.alert('恭喜','您已成功登录!'); 
	   } else{
	      Ext.Msg.alert('失败','登录失败,请重新登录');
	   }
   }
}); 


二.Ext校验

//放在onReady的function(){}中
Ext.QuickTips.init();                       //为组件提供提示信息功能,form的主要提示信息就是客户端验证的错误信息。
Ext.form.Field.prototype.msgTarget='side';         //提示的方式,枚举值为


qtip-当鼠标移动到控件上面时显示提示

title-在浏览器的标题显示,但是测试结果是和qtip一样的

under-在控件的底下显示错误提示

side-在控件右边显示一个错误图标,鼠标指向图标时显示错误提示. 默认值.

id-[element id]错误提示显示在指定id的HTML元件中

1.一个最简单的例子:空验证

//空验证的两个参数
1.allowBlank:false//false则不能为空,默认为true
2.blankText:string//当为空时的错误提示信息

js代码为:
var form1 = new Ext.form.FormPanel({
      width:350,
      renderTo:"form1",
      title:"FormPanel",
      defaults:{xtype:"textfield",inputType:"password"},
      items:[
              {fieldLabel:"不能为空",
                allowBlank:false, //不允许为空
                blankText:"不能为空",  //错误提示信息,默认为This field is required!
                id:"blanktest",
              }
      ]
    });


2.用vtype格式进行简单的验证。
在此举邮件验证的例子,重写上面代码的items配置:
items:[