我是ReactiveSearch库的新手,我实现了带有自动提示的DataSearch组件作为我的站点内SearchBar。我添加了value和onChange,以便将输入值存储为状态,但一旦添加了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>
);
}
}https://stackoverflow.com/questions/55976186
复制相似问题