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