EasyUI 프로젝트 의 사용자 정의 JS

5535 단어 jQueryJSjQueryEasyUi
사용자 정의 방법:
(function($) {  
        $.extend($, {  
            //    ,     
		getArrayIndex :  function (array,value) {
			var index = -1;
			var length = array.length;
			for (var i = 0; i < length; i++) {
				if (array[i].id == value.id) {
					index = i;
					break;
				}
			}
			return index;
		} ,
		removeValue : function (array,value){
			var index = $.getArrayIndex(array,value);
			if(index < 0) return array;
			array.splice(index,1);
			return array;
		}
        });  
    })(jQuery); 
	
	
	function checkExist(array,node){
		var id = node.id;
		var flag = false;
		for(var i = 0;i 
   

 

String.prototype.startsWith = function (substring) {
		var reg = new RegExp("^" + substring);
		return reg.test(this);
	    };
	     
	    String.prototype.endsWith = function (substring) {
		var reg = new RegExp(substring + "$");
		return reg.test(this);
	    };
	    
	    String.prototype.trim = function(){
		var reg = /[\s
\r]+/g; return this.replace(reg, ""); }

 
/** 
	 *      ,  JSON   
	 *   :flag               
	 */  
	$.fn.toJson = function (flag) {  
	    var json = {};  
	    var fields = this.serializeArray();  
	    $.each(fields, function () {  
		if (json[this.name]) {  
		    if (!json[this.name].push) {  
			json[this.name] = [json[this.name]];  
		    }  
		    if (flag || (!flag && this.value != "")) {  
			json[this.name].push(this.value || "");  
		    }  
		} else {  
		    if (flag || (!flag && this.value != "")) {  
			json[this.name] = this.value || "";  
		    }  
		}  
	    });  
	    return json;  
	}; 

 
기타 최적화 방법:
	function comboboxInit(obj,lookupType,form,defaultValue,wid){
		var _obj = $('#'+obj);
		if('' != form  && typeof form != 'undefined'){
			_obj = $("#"+form).find("#"+obj);
		}
		if('' == wid || typeof wid == 'undefined'){
			wid = "150";
		}
		_obj.combobox({
			required:true, 
			width:wid,
			valuefield:'value',
			textField:'text',
			panelHeight:'auto',
			url: root + 'esbService/lookupValComBox.json?lookupType='+lookupType,
			editable:false,
			onLoadSuccess:function(){
				if('' != defaultValue  && typeof defaultValue != 'undefined'){
					_obj.combobox('select',defaultValue);
				}else{
					_obj.combobox('select','');
				}
			}
		});
	}
	
	
	function toggleSenior(but) {
		var check = false;
		if ($(but).attr("checked") == "checked") {
			check = true;
		}
		var rowHeight = 0;
		$(but).parents("form:first").find("tr.advancedCondiction").each(
			function (i, n) {
				rowHeight += 28;
				if (check) {$(n).show();}
				else {$(n).hide();}
			});
		var $layout = $(but).parents(".easyui-layout:first");
		var panelHeight = $layout.layout("panel", "north").panel("options").height;
		if (check) {
			panelHeight += rowHeight;
		} else {
			panelHeight -= rowHeight;
		}
		$layout.layout("panel", "north").panel("resize", {height: panelHeight});
		$layout.layout("resize");
		if(!check){
			clearAdvanced();	
		}
	} 

	
	function doSearch(form){
		var $fm = $(form);
		var fields =$('#queryForm').serializeArray();
		var params = $fm.datagrid('options').queryParams;
		$.each( fields, function(i, field){
			params[field.name] = field.value; 
		});
		$fm.datagrid('reload');
	}
	
	function resetBtn(formId){
		$(formId).find("input[type='text']").each(function(){
			$(this).val("");
		});
		$('#method').combobox('select','');		
		
		if($('#applicationId').length > 0){
			$('#applicationId').combobox('select','');
		}
	}
	
	
  :  
1、  
    formatter:function(val,rec){  
                    return formattime(val);  
                }  
                  
    function formattime(val) {
		var date = new Date(val);
		var tmp = trimDate(date.getFullYear()) 
			+ '-' + trimDate(date.getMonth() + 1) 
			+ '-' + trimDate(date.getDate())
			+ " "+trimDate(date.getHours())
			+ ":"+trimDate(date.getMinutes())
			+ ":"+trimDate(date.getSeconds());
		return tmp;
	}
	
	function trimDate(tmp){
		return parseInt(tmp) < 10 ? "0"+tmp : tmp;
	}    
      
2、  
/** 
 * jackson  JSON          
 * 
 */  
public class JsonDateSerializer extends JsonSerializer {  
    private static DateFormat dateFormat = new SimpleDateFormat(  
            "yyyy-MM-dd HH:mm:ss");  
  
      
    public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)  
            throws IOException, JsonProcessingException {  
        gen.writeString(dateFormat.format(date));  
    }  
}  
  
@Column(name = "BUILD_TIME", nullable = false)  
    @Temporal(TemporalType.TIMESTAMP)  
    @JsonSerialize(using=JsonDateSerializer.class, include=JsonSerialize.Inclusion.NON_NULL)  
    protected java.util.Date  buildTime;  
    
    
    
  

 
。。

좋은 웹페이지 즐겨찾기