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
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?