數據字典分類

var dictionaryGroupMap = {};
var dictionaryDetailMap = {};
$(function() {
	var viewH = document.documentElement.clientHeight;
	var fkRight = document.getElementById("fkRight");
	fkRight.style.height = (viewH - 98) + "px";

	$.ajax({
		url: '/riskManageWeb/dictionary/getAllOptions',
		type: 'POST',
		dataType: 'json',
		data: {},
		success: function(result) {
			//alert(result.length);
			dict = result;
			for (var i = 0; i < result.length; i++) {
				var item = result[i];
				var lxbm = item.lxbm,
					code = item.code,
					name = item.name;
				var array = dictionaryGroupMap[lxbm];
				if (array == null) dictionaryGroupMap[lxbm] = array = [];
				array.push({
					value: code,
					text: name
				});
				var obj = dictionaryDetailMap[lxbm];
				if (obj == null) dictionaryDetailMap[lxbm] = obj = {};
				obj[code] = name;
			}
		}
	})
});

//獲取某類型包括的全部字典數據,格式爲[{text:"text1",value:"value1"},{text:"text1",value:"value1"}],適合表單元素下拉選項。周小建
function getDicts(lxbm){
	return top.dictionaryGroupMap[lxbm] || [];
}

//獲取某類型包括的全部字典數據,格式爲[{text:"text1",value:"value1"},{text:"text1",value:"value1"}],適合查詢框下拉選項,由於有「請選擇」。周小建
function getDictsExt(lxbm){
	var dicts = getDicts(lxbm);
	var array = [{text : "請選擇", value : ""}];
	$.merge(array,dicts);
	return array;
}

//獲取某類型某代碼對應的字典名稱,經過類型和編碼獲取名稱,適合表格中的code轉name等狀況。周小建
function getDict(lxbm,code){
	return (top.dictionaryDetailMap[lxbm]||{})[code];
}
相關文章
相關標籤/搜索