https://codesandbox.io/s/dhananjay-rtb8r?file=/src/App.js
请查看示例代码。我想根据州来绑定城市
答案 0 :(得分:1)
您可以使用Array.filter(),然后使用Array.map()创建子菜单。
示例:
city.filter(city => city.scopeId === state.id).map(city => <MenuItem {...city} />)
编辑:
挂钩示例:
React.useEffect(() => {
const getData = async () => {
const result = await axios.get('api-url/?state=' + state)
// for post requests with params , i suggest you use qs library
// const result = await axios.post('api-url/',qs.stringify({state}))
return result
}
const city = getData()
setState(oldState => ({...oldState,city}))
},[state])