我正在使用材料UI dropdown component并尝试仅在用户填写所有表单并提交表单时运行回调函数.在回调函数上,我打算收集所有表单字段并生成url以调用api. 我的问题是我不能在#560中使用onCh
我的问题是我不能在#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”似乎没有返回任何值.它在控制台中返回此错误:
“未捕获的TypeError:this.refs.jobtype.getValue不是函数”
这是我的下拉组件:
<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;
如果有更好的方法,请建议.