Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SelectField的getValue()_Javascript_Reactjs_Meteor_React Jsx_Material Ui - Fatal编程技术网

Javascript SelectField的getValue()

Javascript SelectField的getValue(),javascript,reactjs,meteor,react-jsx,material-ui,Javascript,Reactjs,Meteor,React Jsx,Material Ui,我只想得到公司的名称并将其保存到数据库中 我正在尝试使用文本,并尝试使用下面的代码获取 sport:this.refs.company.getValue(),而且它工作得很好 然后,我决定用这个公司 它并没有获取数据 constructor(props) { super(props); this.state = { value: 1, }; } submitResume(event) { event.preventDefault(); console.log(this.st

我只想得到公司的名称并将其保存到数据库中

我正在尝试使用文本,并尝试使用下面的代码获取

sport:this.refs.company.getValue(),
而且它工作得很好

然后,我决定用这个公司

它并没有获取数据

constructor(props) {
super(props);
this.state = {
  value: 1,
};
}

submitResume(event) {
    event.preventDefault();
    console.log(this.state.company.getValue({value}));

CreatePost.insert({
        company: this.refs.company.getValue(),

        employee: this.refs.employee.getValue(),

    });
    console.log("Employee Profile Submitted!");
}


handleNameChange = (event, index, value) => this.setState({value});

    <form onSubmit={this.submitResume.bind(this)}>

          <SelectField
                    floatingLabelText="Company Name"
                    className="validate"
                    ref="company"
                    id="company"
                    floatingLabelStyle={{fontSize:20}}
                    fullWidth={true}
                    value={this.state.value}
                    onChange={this.handleNameChange}
                  >
                    <MenuItem value={1} primaryText="Google" />
                    <MenuItem value={2} primaryText="Facebook" />
                    <MenuItem value={3} primaryText="Amazon" />
                    <MenuItem value={4} primaryText="Nest" />
                    <MenuItem value={5} primaryText="Microsoft" />
            </SelectField>

            <TextField
                className="validate"
                type="text"
                ref="employee"
                id="employee"
                hintText="Enter Full Name"
                floatingLabelStyle={{fontSize:20}}
                floatingLabelText="Employee Name"
                multiLine={true}
                rows={1}
                fullWidth={true}
            />
构造函数(道具){
超级(道具);
此.state={
价值:1,
};
}
次摘要(活动){
event.preventDefault();
log(this.state.company.getValue({value}));
CreatePost.insert({
公司:this.refs.company.getValue(),
employee:this.refs.employee.getValue(),
});
log(“已提交员工档案!”);
}
handleNameChange=(事件、索引、值)=>this.setState({value});
对于TextField,它可以正常工作,但对于SelectField则不行。

现在看看这个更新的 您将在参数
索引
事件

constructor(props) {
super(props);
this.state = {
  value: 1,
};
}

submitResume(event) {
    event.preventDefault();
    console.log(this.state.company.getValue({value}));

CreatePost.insert({
        company: this.refs.company.getValue(),

        employee: this.refs.employee.getValue(),

    });
    console.log("Employee Profile Submitted!");
}


handleNameChange(event, index, value) {
  console.log(event);
  console.log(index);
  console.log(value);
  this.setState({value});
}

    <form onSubmit={this.submitResume.bind(this)}>

          <SelectField
                    floatingLabelText="Company Name"
                    className="validate"
                    ref="company"
                    id="company"
                    floatingLabelStyle={{fontSize:20}}
                    fullWidth={true}
                    value={this.state.value}
                    onChange={this.handleNameChange}
                  >
                    <MenuItem value={"Google"} primaryText="Google" />
                    <MenuItem value={"Facebook"} primaryText="Facebook" />
                    <MenuItem value={"Amazon"} primaryText="Amazon" />
                    <MenuItem value={"Nest"} primaryText="Nest" />
                    <MenuItem value={"Microsoft"} primaryText="Microsoft" />
            </SelectField>

            <TextField
                className="validate"
                type="text"
                ref="employee"
                id="employee"
                hintText="Enter Full Name"
                floatingLabelStyle={{fontSize:20}}
                floatingLabelText="Employee Name"
                multiLine={true}
                rows={1}
                fullWidth={true}
            />
构造函数(道具){
超级(道具);
此.state={
价值:1,
};
}
次摘要(活动){
event.preventDefault();
log(this.state.company.getValue({value}));
CreatePost.insert({
公司:this.refs.company.getValue(),
employee:this.refs.employee.getValue(),
});
log(“已提交员工档案!”);
}
handleNameChange(事件、索引、值){
console.log(事件);
控制台日志(索引);
console.log(值);
this.setState({value});
}

我需要做的就是传递文本值,而不是数字

<MenuItem value={"Google"}    primaryText="Google"    />
<MenuItem value={"Facebook"}  primaryText="Facebook"  />
<MenuItem value={"Amazon"}    primaryText="Amazon"    />
<MenuItem value={"Nest"}      primaryText="Nest"      />
<MenuItem value={"Microsoft"} primaryText="Microsoft" />


您是否尝试过使用
selected
属性而不是
value
?this.refs.company.selected()?我需要在何处传递值?您使用selectField作为受控组件(将值存储在状态变量中并在onChange函数中更新),此处不需要ref来获取所选字段中的值使用:
this.state.value
公司:this.refs.company.getValue(),
我可以将其更改为什么?能够通过
console.log(this.state.company.getValue({value}))在控制台中获取值。但在保存到数据库时需要帮助。我如何在控制台日志中显示?仍然无法在控制台日志中获取primaryText作为我的输出。