使用Typehead提交后清除输入数据

博士

我的Typeahead组件:

<Typeahead
              ref="SubjectTypeahead"
              placeholder="Search Subjects"
              onChange={this.onSearchSubjects}
              options={subjectNames}/>

我的onChange函数:

  onSearchSubjects = (values) => {
    if (values.length > 0) {
      this.refs.SubjectTypeahead.getInstance().clear()
      this.props.onSearchSubjects(values[0])
    }
  }

从预输入中选择值时,将调用我的onChange方法,但不会清除所选的值。

知道我做错了什么吗?

谢谢

博士

我的问题现在使用

公共方法要访问组件的公共方法,请向您的typeahead实例添加一个引用,并从给定的处理程序中访问该引用:

<div>
  <Typeahead
    ...
    ref={(typeahead) => this.typeahead = typeahead}
  />
  <button onClick={() => this.typeahead.getInstance().clear()}>
    Clear Typeahead
  </button>
</div>

请注意,您必须使用getInstance来获取预先输入的实例。

blur()

提供一种编程方式来模糊输入。

clear()

提供一种编程方式来重置组件。调用该方法将同时清除文本和选择内容。

focus()

提供一种编程方式来集中输入。

getInput()

提供对组件输入节点的访问。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章