I am trying to get my second dropdown to populate based on what is selected in the first dropdown.
The first dropdown lists the tableNames from the JSON below. I want the second dropdown to be columns for the selected tableName.
For now though I just wanted to see a list of the columns where tableName == 'customer'.
I am trying to use the .filter method along with the .map method to accomplish this, but the second dropdown is empty. Here is the current code I have:
import React from 'react';
import axios from 'axios';
class Search extends React.Component {
constructor(props) {
super(props)
this.state = {
Params: [],
ColumnParams: []
}
}
componentWillMount() {
axios.get('http://localhost:3010/api/schema')
.then(response => {
this.setState({Params: response.data})
})
}
render() {
return (
<div className="Search">
<select>{this.state.Params.map((param, i) =>
<option key={i}>{param.tableName}</option>)}
</select>
<select>{this.state.Params.filter(tn => tn === "customer").map(param =>
<option>{param}</option>)}
And here is the JSON:
[
{
"tableName": "customer",
"columns": [
"customerid",
"title",
"prefix",
"firstname",
"lastname",
"suffix",
"phone",
"email"
]
},
{
"tableName": "product",
"columns": [
"productid",
"name",
"color",
"price",
"productadjective",
"productmaterial"
]
}
]