前端 js 获取数据字典

时间:2025-04-06 20:34:09
var Common = {
		dictCache : {},
		showDictText:function(dictType,value){
	        if(value == "" || value == undefined){
	            return "";
	        }
	        var dicts=(dictType);
	        var rtnStr = "";
            for(var i=0;i<;i++){
                if(dicts[i].id== value){
                    rtnStr += dicts[i].text;
                }
            }
	        return rtnStr;
	    },
	    getDicts:function(dictType){
	        if([dictType] == undefined || [dictType] == null){
	            //不存在,获取缓存
	            $.ajax({
	                type: "GET",
	                url: contextPath + "web/admin/system/codetype/dict",
	                async:false,
	                data:{codeTypeId : dictType},
	                dataType: "json",
	                success:function (datas) {
	                    [dictType] = datas;
	                }
	            });
	        }
	        return [dictType];
	    }
	}

  后台数据格式为[{id:'1',text:'aaa'},{id:'2',text:'bbb'}]