我正在使用react-bootstrap-typeahead
组件来预测用户在文本框中的输入,但我在设置状态时遇到问题,以便用户可以单击下拉菜单中的选项。
到目前为止我的代码就在这里。该函数handleAddtask
在输入时将任务添加到任务列表,但我无法将其分配给预先输入下拉列表。(我仍在学习反应,因此任何有关这方面的资源也将不胜感激)。
import React, { Component } from "react";
import PropTypes from "prop-types";
import { Typeahead } from "react-bootstrap-typeahead";
class AddWatchlistForm extends Component {
constructor(props) {
super(props);
this.state = {
taskName: ""
};
this.handleAddTask = this.handleAddTask.bind(this);
}
static propTypes = {
newTask: PropTypes.func.isRequired
};
render() {
return (
<div className="row">
<div className="col-md-6 col-md-offset-3">
<div style={{ margin: "20px" }}>
<div className="row">
<div className="col-md-6">
<Typeahead
placeholder=""
onChange={e => this.updateTaskName(e)}
onClick={(e => this.updateTask(e), this.handleAddTask)}
value={this.state.taskName}
onKeyPress={e => this.checkEnterKey(e)}
labelKey={option =>
`${option.ticker} ${option.security_type}`
}
options={[
{
"": 0,
ticker: "A",
security_type: "Stock"
},
{
"": 1,
ticker: "AA",
security_type: "Stock"
},
{
"": 2,
ticker: "AAA",
security_type: "Stock"
},
{
"": 3,
ticker: "AAAU",
security_type: "Stock"
},
{
"": 4,
ticker: "AACG",
security_type: "Stock"
}
函数式编程
相关分类