[英]getValue() for SelectField
All I simply want to do is to get the name of the Company and save it to the database 我唯一想做的就是获取公司名称并将其保存到数据库中
I was trying with do with text, and was trying to fetch using the below code 我正在尝试处理文本,并试图使用以下代码进行获取
sport: this.refs.company.getValue(),
and it was working perfect. sport: this.refs.company.getValue(),
它运行完美。
Then I decided to use the SelectField from Material UI for Company 然后,我决定使用Material Material公司的SelectField
And it's not fetching the data. 而且它不是在获取数据。
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}
/>
It's working fine for TextField, but not for SelectField. 对于TextField,它工作正常,但对于SelectField,则不能正常工作。
Now see this updated one you will get your value in one of the parameter value
, index
or event
现在看到此更新的值,您将在参数value
, index
或event
之一中获取值
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}
/>
All I needed to do was to pass the text value instead of a number 我需要做的就是传递文本值而不是数字
<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" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.