gpt4 book ai didi

javascript - SelectField 的 getValue()

转载 作者:行者123 更新时间:2023-12-03 03:56:05 25 4
gpt4 key购买 nike

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

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

sport: this.refs.company.getValue(), 并且运行完美。

然后我决定使用SelectField from Material UI对于公司

并且它没有获取数据。

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 则不然。

最佳答案

现在看看这个更新的您将在参数 valueindexevent

之一中获取值
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}
/>

关于javascript - SelectField 的 getValue(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44939120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com