以校验客户名是否存在为案例:
this.bIsExist = false; //变量为该类所创健的成员变量用与自动校验
fieldLabel:'客户名称' ,name:'AddForm_sCompellation' ,maxLength:50 ,maxLengthText:'客户名称只限于50字以内' ,labelStyle: "text-align: right;" ,width:this.nWideFieldWidth ,validator : this.checkCompellation //"vaidator"为该校验属性,设置校验函数 ,invalidText : '此客户名已存在!' ,allowBlank : false
/** * 功能:触发验证客户是否存在函数事件 * * @version 2012/03/27 */ , checkCompellation : function() { //定义变量值 var compellation = this.ownerCt.find('name','AddForm_sCompellation')[0].getValue(); /*-------------- 发送请求----------------*/ Ext.Ajax .request({ url : 'Customer_sameCompellation.do', params : { compellation : compellation }, method : 'POST', scope : this.ownerCt, success : function(response, options) { var responseArray = Ext.util.JSON .decode(response.responseText); if (responseArray.success == true) // 客户名已经被使用 this.bIsExist = true;// 给变量赋值 else // 客户名可以使用 this.bIsExist = false;// 给变量赋值 } }); /*-------------/ 发送请求----------------*/ return this.ownerCt.bIsExist; }
本人初学ExtJs,记下用于学习还望各位大虾指点!