我正在使用Dropdown
.PrimeReact
我有这段代码,但在Dropdown
我只能显示label
而不是name
.
如何optionsSearch
在菜单中显示变量的每个元素的Dropdown
名称来选择这些名称?
import React, {Component} from 'react';
import {Dropdown} from 'primereact/components/dropdown/Dropdown';
class OptionsExample extends Component {
constructor(props) {
super(props);
this.state = {
optionsSearch: 'FORM_FIELDS'
};
}
onOptionChange = e => {
this.setState({optionsSearch: e.value});
}
render() {
const optionsSearch = [
{key: 'NAME1', name: 'NAME1', label: 'DESCRIPTION1'},
{key: 'NAME2', name: 'NAME2', label: 'DESCRIPTION2'},
{key: 'NAME3', name: 'NAME3', label: 'DESCRIPTION3'}
];
return (
<div>
<div className='ui-g-12 ui-md-12 ui-lg-12'>
<Dropdown value={this.state.optionsSearch} options={optionsSearch} onChange={this.onOptionChange} style={{width: '180px'}} placeholder={`${this.state.optionsSearch}`} />
</div>
</div>
);
}
}
export default OptionsExample;