Extjs实用简单小功能总结

1、数组求最大,最小值,判断是否包含元素

Array.prototype.max = function(){   //最大值
	 return Math.max.apply({},this) 
} 

Array.prototype.min = function(){   //最小值
	 return Math.min.apply({},this) 
}
Array.prototype.S=String.fromCharCode(2); 
Array.prototype.contain = function (e) {
	var r=new RegExp(this.S+e+this.S);  
	return (r.test(this.S+this.join(this.S)+this.S)); 
}

2、过滤Backspace回退键

     其实过滤回退键网上资料很多,一搜一大把,笔者也是从网搜索得到,并做了一定修改,确保在extjs界面里使用正确。

Ext.getDoc().on("keydown",function(e){
      if(e.getKey() == 8 &&( e.getTarget().type =="text" ||e.getTarget().type =="textarea"||e.getTarget().type =="password" )&& !e.getTarget().readOnly&&!e.getTarget().disabled){
                    
       }else if(e.getKey() == 8 &&( e.getTarget().type =="text" ||e.getTarget().type =="textarea"||e.getTarget().type =="password")&& e.getTarget().readOnly){
              e.preventDefault();
       }else if(e.getKey() == 8){
             e.preventDefault();
             Ext.Msg.confirm("提示","您确认需要回到前一页面吗?",function(btn,text){
                  	 if(btn=='yes')
                  	     history.back();
             });
        }                 
});

3、IE下获取name属性元素

var getElementsByName = function(tag, name){   //IE下无法通过name获取标签
    var returns = document.getElementsByName(name);
    if(returns.length > 0) return returns;
    returns = new Array();
    var e = document.getElementsByTagName(tag);
    for(var i = 0; i < e.length; i++){
        if(e[i].getAttribute("name") == name){
            returns[returns.length] = e[i];
        }
    }
    return returns;
}

4、设置可编辑表格是否可编辑

function setgriddisabled(grid,value){
  var cm=Ext.getCmp(grid).getColumnModel();
  var sumcolumn=cm.getColumnCount();
  for(var i=0;i<sumcolumn;i++)
       cm.setEditable(i,value);
}

     这里为什么extjs不提供一个方法可以直接对grid进行是否可编辑的设置呢?疑问
5、自定义clearAll()函数

function clearAll(owt,gri,others){
	if(typeof(others)=='undefined'||others=='')
		others=[];
	if(typeof(gri)=='undefined'||gri=='')
		gri=true;
	var fa=function(cmp){
		var Type=cmp.getXType();		
		if(Type=='textfield'||Type=='combo'||Type=='treecombo'||Type=='datefield'||Type=='numberfield'||Type=='textarea'||Type=='timefield'||Type=='trigger'){				   
			   //cmp.setValue();
			   cmp.value = '';
		       if(cmp.rendered){
		        	cmp.el.dom.value = '';		            
		        }
			   cmp.clearInvalid(); 			   
		}
		if(Type=='datefield'){
			cmp.setMinValue();
			cmp.setMaxValue();
		}
		if(Type=='htmleditor'){
			cmp.setValue();
		}
		if(Type=='grid'&&gri){
			cmp.getStore().removeAll();
		}
	};
	if(Ext.getCmp(owt)){
		Ext.getCmp(owt).findBy(function(cmp,c){
			var Id=cmp.getId();
			if(!others.contain(Id))
			    fa(cmp);
		});
	}else{
		Ext.ComponentMgr.all.each(function(cmp){
			var Id=cmp.getId();
			if(!others.contain(Id))
			    fa(cmp);
		});
	}	
};


使用方法:

    clearAll()------清空该界面全部文本框和表格
     clearAll(‘’,false)----- 清空该界面全部文本框,不清空表格
     clearAll(‘panel’)-----清空id为panel的容器下全部文本框和表格
     clearAll(‘panel’,false,[‘txtBM’,’txtKM’])----- 清空id为panel的容器下全部文本框,不清空表格,不清空id为txtBM,txtKM的组件。

说明:

       对于文本框为什么不用setValue(),这是因为setValue()方法中再次调用了validateValue验证方法,对设置了不允许为空的文本框将显示错误提示,而clearInvalid()就是消除这些提示,所以使用最原始的设置方法。

作者: kunoy
申明:作者写博是为了总结经验,和交流学习之用。
如需转载,请尽量保留此申明,并在文章页面明显位置给出原文连接。谢谢!
 



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值