我正在使用this材料ui下拉列表...当我点击下拉列表并使用箭头键上下移动并按Enter键时,下拉菜单中的值不会被选中。
这是下拉列表的代码
handleChange(value) {
this.props.fetchSubcategories(value)
}
<Field
name="boroughs"
component={SelectField}
type="text"
hintText="Boroughs"
>
{dasboardBoroughts.map((boroughts, i) => {
return(<MenuItem onClick={() => this.handleChange(boroughts.name)} key={i} value={capitalize_Words(boroughts.name)} primaryText={capitalize_Words(boroughts.name)} />)
})}
</Field>
获取子类别的代码
export const fetchSubcategories = (data) => {
const query = `{getSubcategories(category: "${data}") { foursquareData { categories { name }}}}`
return fetch(HOSTNAME, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ query })
})
.then((payload) => {
return payload
})
}
你需要等待javascript中的async
操作。你的api解除了成功的承诺。你需要这样做:
handleChange= value => {
this.props.fetchSubcategories(value).then((res)=>{
this.setState({
menuvalue: //response value
})
})
}
稍后您可以在您的选择值中起诉此状态值。