使用场景
列表返回的状态值是数字,需要显示中文状态

管理中心字典值如下:

实现方法:
1、转换方法

2、列表转换

薅代码吧
/**
* 将数据字典的值格式化
*
@param
{Array}
dicList
数组字典数组
*
@param
{String}
val
待转换的字典值
*
@param
{Boolean}
isString
待转换的字典值是否是字符串类型,默认值true
*/
const
dicFormat = (
dicList,
val,
isString =
true)
=> {
var
data =
'';
if (
val !==
null &&
typeof
val !==
'undefined' &&
val !==
'') {
var
valArray;
if (
isString &&
val.
indexOf(
',') !== -
1) {
valArray =
val.
split(
',');
}
else {
valArray = [
val];
}
for (
let
i =
0;
i<
valArray.
length;
i++) {
let
result =
dicList.
find(
e
=>
e.
value ==
val);
if (
result !==
null &&
typeof
result !==
'undefined') {
data +=
result.
label +
','
}
}
}
return
data.
substring(
0,
data.
length -
1);
};
{{
$tools.
dicFormat(
checkStatus,
scope.
row.
spotcheckstate,
false)}}