我在代码中使用反应选择:
import React, {Component} from 'react';
import Select, {createFilter} from 'react-select';
let _ = require('underscore')
class Test extends Component {
constructor(props) {
super(props);
this.state = {
variables_api: [],
selected_question_obj: null
};
this.handleChange_question = this.handleChange_question.bind(this)
}
componentDidMount() {
fetch('http://127.0.0.1:5000/variables')
.then(res => {
return res.json()})
.then(data => {
this.setState({
variables_api: data
});
})
}
handleChange_question(evt) {
this.setState({
selected_question_obj: evt
});
}
render () {
var key_api = this.state.variables_api.map(obj => {
return {
key_api: obj['index'],
question_api: obj['Label Variabile'],
};
})
var key = …
Run Code Online (Sandbox Code Playgroud)