相当于java中方法的重写,会覆盖以前的方法
定义js的基元
var EditView = function(){
var _this = null;
var $id = null;
var key = null;
var $submit_form = $("#submit_form");
var $url = "notification/notificationtype";
var type = null;
var $add = null;
var $getById = null;
var $upd = null;
this.url = null;
this.dicurl = "system/dic/getDicByCode/";
this.uploadUrl = getUploadUrl();
this.createCusView = null;
this.getMainData = null;
this.init = function(){
key = $.util.request[$id];
type = $.util.request["type"];
_this = this;
$Core.OnPageLoad(function () {
$Core.Loading.HidePageLoading();
});
if (key&&key!="") {
var url = $url+"/getById/" + key;
if($getById != null && $getById != "" && $getById != "null"){
url = $getById+"/"+key;
}
$.get(url, function (data) {
_this.getMainData = data;
$submit_form.form("load", data.data);
if(type=="red"){
$submit_form.form("load", data.data);
$("input").attr("readonly", "readonly");
$(".easyui-combobox").combo('readonly', true);
$(".easyui-combotree").combotree('readonly', true);
$('.easyui-textbox').textbox('readonly');
$(".easyui-my97").my97('disable');
$("#btnSave").hide();
$("button").hide();
/*$("input",$submit_form).each(function(i,n) {
$(n).textbox('disable');
});*/
}
if(type != "add" && _this.renderSelectors){
for(var i=0,len=_this.renderSelectors.length; i<len; i++){
var renderSelector = _this.renderSelectors[i],
dictDatas = $Core.DicCache.get(renderSelector.settings.dictCode);
renderSelector.echoSelect(data, dictDatas);
}
}
});
// var time = setTimeout(function(){
// if(_this.createCusView){
// _this.createCusView();
// }
// clearTimeout(time);
// },300);
}
// else{
// if(_this.createCusView){
// _this.createCusView();
// }
// }
if(_this.createCusView){
_this.createCusView();
}
$("#btnSave").click(function () {
if ($submit_form.form("validate")) {
var url = $url+"/add";
if($add != null && $add != "" && $add != "null") {
url = $add;
}
if (key && key != ""){
url = $url+"/upd";
if ($upd != null && $upd != "" && $upd != "null"){
url = $upd;
}
}
var paras = $submit_form.serialize();
$.post(url, paras, function (data) {
if (data.code == 0) {
$Core.UI.message.success("保存成功!");
}
else {
$Core.UI.message.error(data.msg);
}
});
}
});
}
function getUploadUrl() {
var serviceUrl = $Core.SERVICEPATH();
var preffix = serviceUrl.substring(0,serviceUrl.lastIndexOf("cnten"));
var uploadUrl = preffix + "/plugs/attachment/fileUpload";
return uploadUrl;
}
};
重构基元中的init方法,不重写会继续调用基元的init方法
var _self = new EditView();
$(function () {
_self.createCusView = function(){
$("#approveState").combobox({
url: _self.dicurl+'planState'
});
}
/* _self.init = function(e){
debugger;
key = $.util.request["installApplyId"];
type = $.util.request["type"];
_this = this;
$Core.OnPageLoad(function () {
$Core.Loading.HidePageLoading();
});
if (key&&key!="") {
$.get("security/installapplyvo/getById/" + key, function (data) {
debugger;
_this.getMainData = data;
$("#submit_form").form("load", data.data);
if(type=="red"){
$("input").attr("readonly", "readonly");
$(".easyui-combobox").combo('readonly', true);
$(".easyui-my97").my97('disable');
$(".easyui-combotree").combotree('readonly', true);
$("#btnSave").hide();
$("button").hide();
}
if(type=="edit"){
}
});
}
if(_this.createCusView){
_this.createCusView();
}
}*/
_self.init();
});