小道具を使用して別のテーブルから情報をドロップダウンに入力しようとしています。現在これを持っています。以前は壊れていたので、私はループを逆にしなければならなかった。Populate Dropdown小道具で選択React
import React, { Component, PropTypes } from 'react';
import {
Button,
ControlLabel,
FormGroup,
Form,
FormControl
} from 'react-bootstrap';
class UserForm extends Component {
constructor(props) {
super(props);
}
createPosItems() {
const posItems = [];
console.log('heyyyy', this.props);
for (let i = this.props.position.length; i > this.props.position.length; i--) {
posItems.push(<option key={i} value={this.props.position.i}>{this.props.position.position_name}</option>);
}
return posItems;
}
createTeamItems() {
const teamItems = [];
console.log('whyyyyy', this.props);
for (let i = this.props.team.length; i > this.props.team.length; i--) {
teamItems.push(<option key={i} value={this.props.team.i}>{this.props.team.team_name}</option>);
}
return teamItems;
}
render() {
return (
<div className="row">
<div className="col-lg-12">
<Form>
<FormGroup controlId="employeeFirstName">
<ControlLabel>First Name</ControlLabel>
<FormControl
type="text"
name="firstName"
required=""
value={this.props.user.firstName}
onChange={this.props.onChange}
/>
</FormGroup>
<FormGroup controlId="empEmail">
<ControlLabel>Email</ControlLabel>
<FormControl
type="email"
name="email"
required=""
value={this.props.user.email}
onChange={this.props.onChange}
/>
</FormGroup>
<FormGroup controlId="position">
<ControlLabel>Job Position</ControlLabel>
<FormControl
componentClass="select"
>
<option value="">Select a Position</option>
{this.createPosItems()}
</FormControl>
</FormGroup>
<FormGroup controlId="Team">
<ControlLabel>Team</ControlLabel>
<FormControl
componentClass="select"
>
<option value="">Select a Team</option>
{this.createTeamItems()}
</FormControl>
</FormGroup>
<FormGroup>
<Button
pullRight
type="submit"
className="btn btn-success"
disabled={this.props.saving}
onClick={this.props.onSave}
>Save</Button>
<Button
pullRight
type="submit"
className="btn btn-danger pull-right"
// onClick={this.props.onDelete}
>Delete</Button>
</FormGroup>
</Form>
</div>
</div>
);
}
}
UserForm.propTypes = {
user: React.PropTypes.object.isRequired,
team: React.PropTypes.array.isRequired,
position: React.PropTypes.array.isRequired,
onSave: React.PropTypes.func.isRequired,
onChange: React.PropTypes.func.isRequired,
saving: React.PropTypes.bool
};
export default UserForm;
フォームは別のページの子である。他のすべてのフィールドが動作し、ドロップダウンが予想され、要素が表示されますが、ドロップダウンには入力されません。複数の人の例を使用しようとしたが、それでも実行することはできません。 ありがとうございます!