js的方法重构

相当于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();
});

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wespten

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值