EasyUI项目中的自定义JS

来源:互联网 发布:维棠flv优化破解版 编辑:程序博客网 时间:2024/06/08 08:54

自定义方法:

(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<array.length; i++){var row = array[i];if(row.id == id){flag = true;break; //中断循环}}return flag;}Array.prototype.getIndexByValue= function(value)  {      var index = -1;      for (var i = 0; i < this.length; i++)      {          if (this[i] == value)          {              index = i;              break;          }      }      return index;  };  //在数组中获取指定值的元素索引  Array.prototype.removeValue= function(value)  {  var index = this.getIndexByValue(value);var s = this.splice(index,1);    return s;}  ;

 

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\n\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<Date> {      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;                

 

。。

0 0
原创粉丝点击