[英]getValue() for SelectField
我唯一想做的就是獲取公司名稱並將其保存到數據庫中
我正在嘗試處理文本,並試圖使用以下代碼進行獲取
sport: this.refs.company.getValue(),
它運行完美。
然后,我決定使用Material Material公司的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) => 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}
/>
對於TextField,它工作正常,但對於SelectField,則不能正常工作。
現在看到此更新的值,您將在參數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}
/>
我需要做的就是傳遞文本值而不是數字
<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.