4

我正在使用材质 UI下拉组件,并且仅在用户填写所有表单并提交表单时才尝试运行回调函数。在回调函数上,我打算收集所有表单字段并生成 url 以调用 api。

我的问题是我不能像#560中所述的解决方案那样使用 onChange,因为我只想在用户单击提交按钮时收集所有详细信息。奇怪的是,目前,我能够获得所有其他表单元素的值,如滑块、使用 material-ui 但只有下拉菜单的文本字段似乎不起作用。

我的回调函数:

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,posted_date,radius,salary”中返回值,但恰好是下拉列表的“jobtype”似乎没有返回任何值。它在控制台中返回此错误:“Uncaught TypeError: this.refs.jobtype.getValue is not a function”

这是我的下拉组件:

<DropDownMenu menuItems={menuItems} ref="jobtype" />
4

1 回答 1

1

可能不是正确的方法,但我想通了

console.log(this.refs.jobtype)(在我的情况下,jobtype 是下拉列表的参考值)

给出了以下结果。

R…s.c…s.Constructor {props: Object, context: Object, state: Object, refs: Object, _reactInternalInstance: ReactCompositeComponentWrapper}

检查它,我在“selectedIndex”属性内的状态对象内找到了有效负载索引(所选项目的索引号)的值。我使用以下代码访问选定的索引:

var jobtype = this.refs.jobtype.state.selectedIndex;  

如果有更好的方法可以做到这一点,请提出建议。

于 2015-09-18T04:14:13.450 回答