angularJs通过过滤器实现获取数据字典

前端之家收集整理的这篇文章主要介绍了angularJs通过过滤器实现获取数据字典前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//缓存数据字典 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; } }); 原文链接:https://www.f2er.com/angularjs/148837.html

猜你在找的Angularjs相关文章