【问题标题】:React-Typescript Auto-suggest display results after typing three lettersReact-Typescript 输入三个字母后自动提示显示结果
【发布时间】:2018-06-19 12:21:26
【问题描述】:

我在 NPM create-react-ts 命令之后创建了两个 react-typescript 应用程序, 之后,我为一个应用程序安装了 react-search-box 软件包之一,然后为其他应用程序安装了 react-autosuggest

做了几处修改,但需要帮助。我需要包含一个功能,即只有在有人输入三个或更多字母后,两个搜索框才应在下拉列表中显示结果。 例如:- 最初有人键入“A”,然后显示结果,但现在应该在有人键入三个字母“TRU”或“ABC”等时显示结果

知道如何修改现有应用程序吗??

下面是我的应用程序的结构.....

 export class myApp extends React.Component<any,any> {  
  constructor() {
  super();
  this.state = {
  data: [],
  loading: false
};}
 componentDidMount(){
this.setState({
  loading: true});

fetch('serviceUrl......')
.then(res => res.json())
.then(data => {
  this.setState({
    data: data.items, 
    loading: false
  });
})}handleChange(event) {
console.log(event);}

  render(){return (
<div className="div_search">
          <Search
            data={ this.state.data }                
            onChange={ this.handleChange.bind(this.state.data) }
            placeholder="Enter the name..."
            class="search_box"
            searchKey="fName" 
          />)}

fName 是保留从服务器返回的所有名字的值

【问题讨论】:

    标签: reactjs typescript react-native react-redux


    【解决方案1】:

    您可以编写逻辑onChange事件并获取输入的当前值并在输入长度为3时进行状态更改。

    【讨论】:

    • 嗨@sureshkumar,是的,包含 onChange 事件的概念是正确的,您是否有任何链接说明您描述的方法?
    • 您能否提供您在输入时获得结果的代码。
    • 你可以关注这个link
    • 感谢 @sureshkumar 它为我工作,但需要关于 react-search-box 的帮助,我正在使用默认的“componentDidMount”从服务中获取记录..然后是 onChange 任何线索如何应用您的方法它。!
    • @sureshkumar - 请再次查看我的帖子,我包含了代码,如果需要其他任何内容,请告诉我......
    猜你喜欢
    • 2020-07-24
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 2021-04-29
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    • 2018-03-05
    相关资源
    最近更新 更多