javascript - material ui dropdown on enter click not selecting value
问题描述
I am using this material ui dropdown... When I click on the dropdown and moving up and down with the arrow keys and press enter then the value doesn't get selected in the dropdown menu.
Here is the code for the dropdown
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>
Code for fetchSubcategories
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
})
}
解决方案
您需要等待async
javascript中的操作。您的 api 在成功时解决了一个承诺。你需要这样做:
handleChange= value => {
this.props.fetchSubcategories(value).then((res)=>{
this.setState({
menuvalue: //response value
})
})
}
稍后您可以在您的选择值中起诉此状态值。
推荐阅读
- sql - sql teradata 正则表达式包含模式匹配
- python-2.6 - 如何将列动态附加到 .csv 文件?
- javascript - 通过检查映射中的匹配值从数组中过滤对象(JavaScript)
- hp-uft - UFT 14.52 监视 Java 对象但未添加它
- java - 从片段到片段返回变量
- javascript - React Native Geolocation GetCurrentPosition EnableHighAccuracy
- firebase - 使用 CDN 通过下载 URL 访问 Firebase 存储对象?
- c# - 如何解析一个有序的txt文件
- json - 将 json 转换为 swift 对象返回 nill?
- ruby - Vagrant 多机配置每台机器