angularJs通过过滤器实现获取数据字典
发布时间:2020-12-17 09:55:41 所属栏目:安全 来源:网络整理
导读://缓存数据字典 var dicMap = JSON.parse(dictData); /** * 获取字典值的方法 * @param key 关键字 * @param type 大类 * @return 返回结果对像 success为true,则value为字典值 */ arm.getDict = function(key,type) { var result = {}; result.success = fa
//缓存数据字典 var dicMap = JSON.parse(dictData); /** * 获取字典值的方法 * @param key 关键字 * @param type 大类 * @return 返回结果对像 success为true,则value为字典值 */ arm.getDict = function(key,type) { var result = {}; result.success = false; var dictValue; if (dicMap[type] && dicMap[type][key]) { dictValue = dicMap[type][key].label; } if (dictValue) { result.success = true; result.value = dictValue; } return result; }; // 注册表格字典值过滤器 arm.filter('Dict',function($rootScope,$http,$q) { return function(input,type) { var returnVal = input; if (type) { var result = arm.getDict(input,type); if (result.success) { returnVal = result.value; } } return returnVal; } }); //注册下拉框表格字典值 arm.filter('dictOption',function() { /** * data 循环的列表 * key 对像的key属性的属性名 * name 对像的显示属性的属性名 * type 字典大类 */ return function(data,key,name,type) { if (data && type) { //循环对每个选项进行过滤,过滤的结题是按 angular.forEach(data,function(item,index) { //如果有这2个属性 if (item[key] && item[name]) { //如是取到字典值 var result = arm.getDict(item[key],type); if (result.success) { item[name] = result.value; } } }); } return data; } }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |