优化字典 select 和 text

This commit is contained in:
sin
2019-03-15 22:59:37 +08:00
parent 888151f523
commit 70b5ea48b3
19 changed files with 184 additions and 216 deletions

View File

@@ -1,20 +1,32 @@
import React, { PureComponent } from 'react';
import { Select } from 'antd';
import DictionaryContext from './DictionaryContext';
export default class DictionarySelect extends PureComponent {
renderOptions() {
const { list } = this.props;
return list.map(item => {
return (
<Select.Option key={item.value} value={item.value}>
{item.text}
</Select.Option>
);
});
renderSelect(children) {
return <Select {...this.props}>{children}</Select>;
}
render() {
const options = this.renderOptions();
return <Select {...this.props}>{options}</Select>;
const { dicKey } = this.props;
return (
<DictionaryContext.Consumer>
{context => {
const dicValues = context[dicKey];
let nodes = [];
if (dicValues) {
nodes = Object.keys(dicValues).map(value => {
const text = dicValues[value];
return (
<Select.Option key={value} value={value}>
{text}
</Select.Option>
);
});
}
return this.renderSelect(nodes);
}}
</DictionaryContext.Consumer>
);
}
}