1

https://codesandbox.io/s/dhananjay-rtb8r?file=/src/App.js

请查看示例代码。我想根据州绑定城市

4

1 回答 1

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])
于 2020-05-03T11:37:53.530 回答