您的位置:首页 > Web前端 > AngularJS

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;

}

});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: