angularJs通过过滤器实现获取数据字典
2016-09-19 11:24
579 查看
//缓存数据字典
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;
}
});
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;
}
});
相关文章推荐
- 如何通过字典表来获取下拉数据的实现
- 过滤器通过HttpServletResponseWrapper包装HttpServletResponse实现获取response中的返回数据,以及对数据进行gzip压缩
- 通过反射快速实现DataGridView数据的添加,获取及序列化
- Vue.js 通过jQuery ajax获取数据实现更新后重新渲染页面
- Android设备通过NTRIP协议获取差分数据实现高精度定位
- mui上拉加载通过ajax获取数据,实现分页
- js实现手机端可以上拉刷新,动态通过ajax从后台获取数据
- Hibernate中通过HQL/JPQL查询的方式实现动态数据获取
- Hibernate中通过FetchProfile的方式实现动态数据获取
- Hibernate中通过JPA entity graph的方式实现动态数据获取
- java通过JDBC获取MySQL的数据实现
- 通过AngularJS实现前端与后台的数据对接(一)——预备工作篇
- 通过AngularJS实现前端与后台的数据对接(二)——服务(service,$http)篇
- java通过JDBC获取MySQL的数据实现
- C#和C实现通过CRC-16 (Modbus)获取CRC值并校验数据(代码)
- 无限遍历,Python实现在多维嵌套字典、列表、元组的JSON中获取数据
- 通过angularjs添加表格数据实现增删总金额
- [置顶] 无限遍历,python实现在多维嵌套字典、列表、元组的JSON中获取数据
- 无限遍历,python实现在多维嵌套字典、列表、元组的JSON中获取数据
- SparkStreaming通过Flume获取数据(单机,push和poll两种方式)的实现