提交 | 用户 | 时间
|
e57a89
|
1 |
import DictOptions from './DictOptions' |
懒 |
2 |
import DictData from './DictData' |
|
3 |
|
|
4 |
export default function(dict, dictMeta) { |
|
5 |
const label = determineDictField(dict, dictMeta.labelField, ...DictOptions.DEFAULT_LABEL_FIELDS) |
|
6 |
const value = determineDictField(dict, dictMeta.valueField, ...DictOptions.DEFAULT_VALUE_FIELDS) |
|
7 |
return new DictData(dict[label], dict[value], dict) |
|
8 |
} |
|
9 |
|
|
10 |
/** |
|
11 |
* 确定字典字段 |
|
12 |
* @param {DictData} dict |
|
13 |
* @param {...String} fields |
|
14 |
*/ |
|
15 |
function determineDictField(dict, ...fields) { |
|
16 |
return fields.find(f => Object.prototype.hasOwnProperty.call(dict, f)) |
|
17 |
} |