需要获取下拉菜单的值而不使用onChange回调 – (material-ui rea
发布时间:2020-12-15 09:35:04 所属栏目:百科 来源:网络整理
导读:我正在使用材料UI dropdown component并尝试仅在用户填写所有表单并提交表单时运行回调函数.在回调函数上,我打算收集所有表单字段并生成url以调用api. 我的问题是我不能在#560中使用onChange作为声明的解决方案,因为我只想在用户点击提交按钮时收集所有细节.
我正在使用材料UI
dropdown component并尝试仅在用户填写所有表单并提交表单时运行回调函数.在回调函数上,我打算收集所有表单字段并生成url以调用api.
我的问题是我不能在#560中使用onChange作为声明的解决方案,因为我只想在用户点击提交按钮时收集所有细节.同样奇怪的是,此刻,我能够获得所有其他表单元素的值,如使用material-ui的slider,textfield,但只有dropdown似乎不起作用. 我的回电功能: handleFilter: function(event){ event.preventDefault(); var location = this.refs.location.getValue(); var posted_date = this.refs.posted_date.getValue(); var radius = this.refs.distance.getValue(); var salary = this.refs.salary.getValue(); var jobtype = this.refs.jobtype.getValue(); console.log(jobtype); } 在上面的函数“location,published_date,radius,salary”中返回值,但恰好是下拉列表的“jobtype”似乎没有返回任何值.它在控制台中返回此错误: 这是我的下拉组件: <DropDownMenu menuItems={menuItems} ref="jobtype" /> 解决方法
可能不是正确的方法,但我想通了
console.log(this.refs.jobtype)(jobtype是我的下拉列表的refs值) 给出了以下结果. R…s.c…s.Constructor {props: Object,context: Object,state: Object,refs: Object,_reactInternalInstance: ReactCompositeComponentWrapper} 在它的“selectedIndex”属性中,我在状态对象内找到了有效负载索引(所选项的索引号)的值.我使用以下代码来访问所选索引: var jobtype = this.refs.jobtype.state.selectedIndex; 如果有更好的方法,请建议. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |