|
@@ -1,25 +1,36 @@
|
|
|
import XEUtils from "xe-utils";
|
|
|
|
|
|
interface Option {
|
|
|
+ // 数组中的 code
|
|
|
listCode: string,
|
|
|
+ // 数组中的 name
|
|
|
listValue: string
|
|
|
}
|
|
|
|
|
|
const defaultValue: Option = {listCode: 'code', listValue: 'name'}
|
|
|
|
|
|
-const findValueByListCode = (arr: any[], code: string | number, option: Option = defaultValue): string => {
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @param arr 数组
|
|
|
+ * @param code 需要寻找的值
|
|
|
+ * @param option 配置
|
|
|
+ */
|
|
|
+const findValueByListCode = (arr: any[] | object, code: string | number, option: Option = defaultValue): string => {
|
|
|
const {listCode, listValue} = option
|
|
|
if (XEUtils.isEmpty(arr)) {
|
|
|
return '';
|
|
|
}
|
|
|
+
|
|
|
if (!XEUtils.isArray(arr)) {
|
|
|
return '';
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
if (typeof code === 'undefined' || code === null) {
|
|
|
return '';
|
|
|
}
|
|
|
|
|
|
- for (let i = 0, len = arr.length; i < len; i++) {
|
|
|
+ for (let i: number = 0, len: number = arr.length; i < len; i++) {
|
|
|
if (arr[i][listCode] === code) {
|
|
|
return arr[i][listValue];
|
|
|
}
|