我正在使用反应选择。
目前我正在从 elasticsearch 获取数据并将其设置为状态:
var new_titles = []
body.hits.hits.forEach(function(obj){ // looping through elasticsearch
new_titles.push({value: obj._source.title_id, label: obj._source.title_name})
})
this.setState({titleResults: new_titles})
后来我使用this.state.titleResults
并将其传递给我的 React-Select 组件:
<Select autofocus optionComponent={DropdownOptions} options={this.state.titleResults} simpleValue clearable={this.state.clearable} name="selected-state" value={this.state.selectedTitleValue} onChange={this.handleTitleChosen} searchable={this.state.searchable} />
这工作正常。但是现在我想在用户搜索我的 React-Select 组件选项时传递与此标题相关的额外元数据。像这样的东西:
我只是传入{value: obj._source.title_id, label: obj._source.title_name}
,但我想传入更多信息以供我的DropdownOption
组件使用:
const DropdownOptions = React.createClass({
propTypes: {
children: React.PropTypes.node,
className: React.PropTypes.string,
isDisabled: React.PropTypes.bool,
isFocused: React.PropTypes.bool,
isSelected: React.PropTypes.bool,
onFocus: React.PropTypes.func,
onSelect: React.PropTypes.func,
option: React.PropTypes.object.isRequired,
},
handleMouseDown (event) {
event.preventDefault();
event.stopPropagation();
this.props.onSelect(this.props.option, event);
},
handleMouseEnter (event) {
this.props.onFocus(this.props.option, event);
},
handleMouseMove (event) {
if (this.props.isFocused) return;
this.props.onFocus(this.props.option, event);
},
render () {
return (
<div className={this.props.className}
onMouseDown={this.handleMouseDown}
onMouseEnter={this.handleMouseEnter}
onMouseMove={this.handleMouseMove}
title={this.props.option.title}>
<span>Testing Text</span>
{this.props.children}
</div>
);
}
});
您将如何将更多信息传递到此组件中?