javascript - react-bootstrap Add Options to Select - ReactJS - Stack Overflow

I'm working with react-bootstrap and ReactJS. I was expecting the select to take the options as an

I'm working with react-bootstrap and ReactJS. I was expecting the select to take the options as an argument, but not seeing a way to populate the options. This is the code I have thus far. How do I pass in the data

render() {

    return (
        <div>
            <Button bsStyle="primary" onClick={this.open}>Add Parameter</Button>
            <Modal show={this.state.showModal} onHide={this.close}>
                <Modal.Header>
                    <Modal.Title>Add / Edit Parameter</Modal.Title>
                </Modal.Header>
                <Modal.Body>
                    <form>
                        <FormGroup controlId="parameterType">
                            <ControlLabel>Type</ControlLabel>
                            <FormControl ponentClass="select" placeholder="Type">
                                <option value="select">select</option>
                                <option value="other">...</option>
                            </FormControl>
                        </FormGroup>
                    </form>
                </Modal.Body>
                <Modal.Footer>
                    <Button bsStyle="primary" onClick={this.close}>Save Changes</Button>
                </Modal.Footer>
            </Modal>
        </div>
    )
}

I'm working with react-bootstrap and ReactJS. I was expecting the select to take the options as an argument, but not seeing a way to populate the options. This is the code I have thus far. How do I pass in the data

render() {

    return (
        <div>
            <Button bsStyle="primary" onClick={this.open}>Add Parameter</Button>
            <Modal show={this.state.showModal} onHide={this.close}>
                <Modal.Header>
                    <Modal.Title>Add / Edit Parameter</Modal.Title>
                </Modal.Header>
                <Modal.Body>
                    <form>
                        <FormGroup controlId="parameterType">
                            <ControlLabel>Type</ControlLabel>
                            <FormControl ponentClass="select" placeholder="Type">
                                <option value="select">select</option>
                                <option value="other">...</option>
                            </FormControl>
                        </FormGroup>
                    </form>
                </Modal.Body>
                <Modal.Footer>
                    <Button bsStyle="primary" onClick={this.close}>Save Changes</Button>
                </Modal.Footer>
            </Modal>
        </div>
    )
}
Share Improve this question asked Feb 20, 2017 at 1:16 jkratz55jkratz55 8814 gold badges14 silver badges30 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

you'd map over your data to produce the options programmatically. Suppose your options are in an array: options=[{value: 'select'}, {value: 'other'}]

<FormControl ponentClass="select" placeholder="Type">
  {
     options.map((option, index) => {
        return (<option key={index} value={option.value}>{option.value}</option>)
     })
  }
</FormControl>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742260470a4410808.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信