您当前的位置: 首页 > 

wespten

暂无认证

  • 0浏览

    0关注

    899博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

js字典项缓冲插件的开发与编写

wespten 发布时间:2018-10-28 13:46:25 ,浏览量:0

js字典项缓冲插件的开发与编写

              //初始化字典数据
                $Core.DicCache.initDictionary("installdevName,publicserviceName,stockState,stockDeviceState,propertyAscription,installdevName", function () {  
                	$.each(data.data.deviceUserList, function (k, j) {	
                		var deviceName = j.deviceName;
                		var propertyAscription = j.propertyAscription;
                		var appendRow =" "+$Core.DicCache.get("installdevName")[deviceName]+
                		""+j.deviceNumber+
                		""+j.assetsNumber+
                		" "+j.company+
                		" "+j.deviceSpec+
                		" "+$Core.DicCache.get("propertyAscription")[propertyAscription]+
                		""+j.number+
                		" "+j.unitMoney+
                		""+j.installMoney+
                		" "+j.total+
                		""
                		$("#newRow").after(appendRow);
                	});
                });
(function (window, $, undefined) {
var _Core = function () {
};
window.$Core = new _Core();
    var _cache = function () {
        var cache = {};
        this.set = function(dicobj) {
            if ($.util.isObject(dicobj)) {
                if (dicobj !== undefined && dicobj.data !== undefined)
                    $.each(dicobj.data,
                        function(i, n) {
                            var tempitem = cache[i] = cache[i] || {};
                            tempitem.originalData = n;
                            $.each(n,
                                function(j, k) {
                                    //console.log(k);
                                    //k[k.id] = k.text;
                                    if (k.id !== undefined && k.id !== "" && k.text !== undefined)
                                        tempitem[k.id] = k.text;
                                    if (k.children) {
                                        recursiondic(tempitem, k.children);
                                    }

                                });
                        });
            } else {
                throw "字典初始化仅支持对象信息";
            }
        };
        /**
         * 递归子节点
         * @param {any} obj
         * @param {any} children
         */
        function recursiondic(obj, children) {
            $.each(children,
                function (j, k) {
                    //console.log(k);
                    if (k.id !== undefined && k.id !== "" && k.text !== undefined)
                        obj[k.id] = k.text;
                    if (k.children) {
                        recursiondic(obj, k.children);
                    }
                });
        }

        /**
         * 获取字典数据 x.originalData 是原始数据结构 
         * @param {any} dicCode
         */
        this.get = function(dicCode) {
            return $.extend({}, cache[dicCode]);
        };
        /**
         * @param {string} diccodes
         * @param {function} func
         */
        this.initDictionary = function (diccodes, func) {
            $.get("system/dic/getDicByCodes/" + diccodes,
                function (data) {
                    $Core.DicCache.set(data);
                    if (func !== undefined)
                        func(data);
                });
        };
    }
    $Core.DicCache = new _cache();
})(window, jQuery);


 

tempitem = cache[i] = cache[i] || {};初始化对象

$.extend({}, cache[dicCode]);获取数组中的对象

    //初始化字典数据
    $Core.DicCache.initDictionary("customerType,,yesno", function () {
        debugger;
    	$("#customerType").combobox({
            data: $Core.DicCache.get("customerType").originalData
    });
$Core.DicCache.get("devapplyState")[approveState]

 

 

 

 

必须要初始化new实例才能调用

实例化后通过全局window调用

 

后台实现:

	@GetMapping("/getDicByCodes/{dictCodes}")
	public AssembleJSON getDicByCodes(@PathVariable String dictCodes) {
		SessionData sessionData = getCurrUserData();
		int userId = sessionData.getUserId();
		String orgManageDataCode = sessionData.getOrgManageDataCode();
		String orgDataCode = sessionData.getOrgDataCode();
		Integer orgLevel = sessionData.getOrgLevel();
		return AssembleJSON.SUCCESS(service.getDicByCodes(dictCodes,userId,orgManageDataCode,orgDataCode,orgLevel));
	}
Hashtable getDicByCodes(String dictCodes,Integer userId, String orgManageDataCode,String orgDataCode, Integer orgLevel);

	@Override
	public Hashtable getDicByCodes(String dictCodes,Integer userId, String orgManageDataCode,String orgDataCode, Integer orgLevel){
		Hashtable hashtable = new Hashtable();
		String[] codes = dictCodes.split(",");
		List dicItems = new ArrayList();
		for(String code : codes){
			dicItems = getDicByCode(code,userId,orgManageDataCode,orgDataCode,orgLevel);
			if(dicItems != null){
				hashtable.put(code, dicItems);
			}
		}
		return hashtable;
	}
	
	@Override
	public List getDicByCode(String dictCode,Integer userId, String orgManageDataCode,String orgDataCode, Integer orgLevel) {
		Dictionary dictionary1 = new Dictionary();
		dictionary1.setDictCode(dictCode);
		Dictionary dictionary = mapper.selectOne(dictionary1);
		if(dictionary == null){
			return null;
		}
		List listDic = new ArrayList();
		if(dictionary != null){		
			if(dictionary.getDictType() == 1){
				List list = dictionaryItemMapper.selectDictionaryItemAll(dictCode);
				getDicList(list,listDic);
			}else{
				String source1 = dictionary.gettSource();
				if(source1 == null || "".equals(source1)){
					return null;
				}
				String source = "";
				String source2 = "";
				String source3 = "";
				String source4 = "";
				source2 = source1.replace("{@sys_orgDataCode@}", orgDataCode);
				source3 = source2.replace("{@sys_userId@}", String.valueOf(userId));			
				source4 = source3.replace("{@sys_orgManageDataCode@}", orgManageDataCode);
				source = source4.replace("{@sys_orgLevel@}",String.valueOf(orgLevel));
				String code = dictionary.getfCode();
				String name = dictionary.getfName();
				String sort = dictionary.getfSort();
				String pField = dictionary.getpField();
			    List list = new ArrayList();
			    if(sort == null || "".equals(sort)){
			    	if(pField == null || "".equals(pField)){
			    		list = mapper.selectDictionary(code, name, source,"'"+sort+"'");
			    	}else{
			    		list = mapper.selectDictionaryParent(code, name, source,"'"+sort+"'",pField);
			    	}	   
			    }else{
			    	if(pField == null || "".equals(pField)){
			    		list = mapper.selectDictionary(code, name, source,sort);
			    	}else{
			    		list = mapper.selectDictionaryParent(code, name, source,sort,pField);
			    	}	  
			    }			   
			getDicList(list,listDic);				
			}
		}
		return listDic;
	}
	public void getDicList(List list,List listDic){
		if(list.size() == 1){
			for(DictionaryItem dItem : list){				
					DicItem dic = new DicItem();
					dic.setId(dItem.getItemCode());
					dic.setText(dItem.getItemName());
					listDic.add(dic);
			}
		}else{
			boolean flag = true;
			for(DictionaryItem dItem : list){	
				if(dItem.getParentCode() == null || "".equals(dItem.getParentCode())){
					DicItem dic = new DicItem();
					dic.setId(dItem.getItemCode());
					dic.setText(dItem.getItemName());
					listDic.add(dic);
					getChild(list,dic);
					flag = false;
				}
		    }
			if(flag){
				if(list.size() > 0){
					int min = list.get(0).getParentCode().toString().length();
					for(int i=1; i            
关注
打赏
1665965058
查看更多评论
0.0425s