SearchField.js
上传用户:shuoshiled
上传日期:2018-01-28
资源大小:10124k
文件大小:2k
源码类别:

中间件编程

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.0.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */ Ext.ns('Ext.ux.form');
  2. Ext.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
  3.     initComponent : function(){
  4.         Ext.ux.form.SearchField.superclass.initComponent.call(this);
  5.         this.on('specialkey', function(f, e){
  6.             if(e.getKey() == e.ENTER){
  7.                 this.onTrigger2Click();
  8.             }
  9.         }, this);
  10.     },
  11.     validationEvent:false,
  12.     validateOnBlur:false,
  13.     trigger1Class:'x-form-clear-trigger',
  14.     trigger2Class:'x-form-search-trigger',
  15.     hideTrigger1:true,
  16.     width:180,
  17.     hasSearch : false,
  18.     paramName : 'query',
  19.     onTrigger1Click : function(){
  20.         if(this.hasSearch){
  21.             this.el.dom.value = '';
  22.             var o = {start: 0};
  23.             this.store.baseParams = this.store.baseParams || {};
  24.             this.store.baseParams[this.paramName] = '';
  25.             this.store.reload({params:o});
  26.             this.triggers[0].hide();
  27.             this.hasSearch = false;
  28.         }
  29.     },
  30.     onTrigger2Click : function(){
  31.         var v = this.getRawValue();
  32.         if(v.length < 1){
  33.             this.onTrigger1Click();
  34.             return;
  35.         }
  36.         var o = {start: 0};
  37.         this.store.baseParams = this.store.baseParams || {};
  38.         this.store.baseParams[this.paramName] = v;
  39.         this.store.reload({params:o});
  40.         this.hasSearch = true;
  41.         this.triggers[0].show();
  42.     }
  43. });