我是 ReactiveSearch 库的新手,我使用自动建议实现了 DataSearch 组件作为我的站内 SearchBar。我添加了value
andonChange
以将输入值存储为状态,但是一旦添加了value
道具,我就无法再在搜索栏中输入内容了。怎么了?
我也想知道当我点击其中一个建议触发某个事件时,我可以使用什么样的回调函数,我试过了onClick
,但没有奏效。这是我的代码,任何帮助表示赞赏!
import * as React from 'react';
import {
ReactiveBase,
DataSearch,
} from '@appbaseio/reactivesearch';
import './SearchBar.scss';
export default class SearchBar extends React.Component {
constructor(props) {
super(props);
this.state = { searchTerm: '' };
}
handleInputChange = (event) => {
this.setState({ searchTerm: event.target.value });
};
handleSearch = () => {
// do something...
};
public render() {
return (
<React.Fragment>
<ReactiveBase
app="rooms,floors,assets"
url="http://localhost:9200"
headers={{
'Access-Control-Allow-Origin': '*'
}}
style={{ display: 'inline' }}
>
<DataSearch
componentId="SearchRoom"
dataField={['roomName', 'roomNumber', 'floorName', 'assetName']}
placeholder="Search for rooms or assets"
style={{ width: 500, display: 'inline-block' }}
fuzziness={1}
value={this.state.searchTerm}
onChange={this.handleInputChange}
//how to trigger handleSearch when I click one of the suggestions?
/>
</ReactiveBase>
</React.Fragment>
);
}
}