jquery的this的使用

jquery的this的使用

this可以重写'父类'的方法

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(){
        if(parent.$("#addwind_frame").contents().length>0){
            $id =  $("#cntenIdKey",parent.$("#addwind_frame").parent().parent().parent()).val();
            $url = $("#cntenUrl",parent.$("#addwind_frame").parent().parent().parent()).val();
            $upd = $("#cntenUpd",parent.$("#addwind_frame").parent().parent().parent()).val();
            $add = $("#cntenAdd",parent.$("#addwind_frame").parent().parent().parent()).val();
            $getById = $("#cntenById",parent.$("#addwind_frame").parent().parent().parent()).val();
        }else if(parent.$("#editwind_frame").contents().length>0) {
            $id =  $("#cntenIdKey",parent.$("#editwind_frame").parent().parent().parent()).val();
            $url = $("#cntenUrl",parent.$("#editwind_frame").parent().parent().parent()).val();
            $upd = $("#cntenUpd",parent.$("#editwind_frame").parent().parent().parent()).val();
            $add = $("#cntenAdd",parent.$("#editwind_frame").parent().parent().parent()).val();
            $getById = $("#cntenById",parent.$("#editwind_frame").parent().parent().parent()).val();
        }else{
            $id =  $("#cntenIdKey",parent.$("#redwind_frame").parent().parent().parent()).val();
            $url = $("#cntenUrl",parent.$("#redwind_frame").parent().parent().parent()).val();
            $upd = $("#cntenUpd",parent.$("#redwind_frame").parent().parent().parent()).val();
            $add = $("#cntenAdd",parent.$("#redwind_frame").parent().parent().parent()).val();
            $getById = $("#cntenById",parent.$("#redwind_frame").parent().parent().parent()).val();
        }

        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);
                	}
                }
            });

        if(_this.createCusView){
            _this.createCusView();
        }
 
    }

    function getUploadUrl() {
        var serviceUrl = $Core.SERVICEPATH();
        var preffix = serviceUrl.substring(0,serviceUrl.lastIndexOf("cnten"));
        var uploadUrl = preffix + "zuul/cnten/plugs/attachment/fileUpload";
        return uploadUrl;
    }
};
var _self = new EditView();
$(function () {
    _self.createCusView = function(){
    	$("#approveState").combobox({
            url: _self.dicurl+'userdevState'
        });
        	$("#customerType").combobox({
        		url: _self.dicurl+'customerType'
        	});
        $("#bottleLibraryWindowFire").combobox({
            url: _self.dicurl+'yesno'
        });
        $("#bottleLibraryWindowOutOpen").combobox({
            url: _self.dicurl+'yesno'
        });
        $("#bottleLibraryGroove").combobox({
            url: _self.dicurl+'yesno'
        });
        $("#installDate").my97({
            minDate:'#F{$(\'#productionDate\').my97(\'getValue\')}'
        });

    }
    
    _self.init = function(){
        key = $.util.request["deviceInstallCheckId"];
        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();
	

});

调用重写的createCusView方法

var EditView = function(){
this.uploadUrl = getUploadUrl();
 function getUploadUrl() {
        var serviceUrl = $Core.SERVICEPATH();
        var preffix = serviceUrl.substring(0,serviceUrl.lastIndexOf("cnten"));
        var uploadUrl = preffix + "zuul/plugs/attachment/fileUpload";
        return uploadUrl;
    }
}

var _self = new EditView();
$(function () {
_self.uploadUrl
});

猜你喜欢

转载自blog.csdn.net/qq_35029061/article/details/83413852