【发布时间】:2019-10-15 19:17:19
【问题描述】:
componentDidMount(){
this.setState({
values2:[{ name: 'Q1', id: 1 },
{ name: 'Q2', id: 2 },
{ name: 'Q3', id: 3 },
{ name: 'Q4', id: 4 }]
});
} setQuarterData(){
var optionTemplate2 = this.state.values2.map(v => (
<option value={v.id} key={v.id}>{v.name}</option>
));
document.getElementById('quarter').innerHTML(optionTemplate2);
// document.getElementById('quarter').style.background="red";
console.log(optionTemplate2);
}
我在 optionTemplate2 中获取数据,但我无法在 select 中设置
0: {$$typeof: Symbol(react.element), type: "option", key: "1", ref: null, props: {…}, …} 1: {$$typeof: Symbol(react.element), type: "option", key: "2", ref: null, props: {…}, …} 2: {$$typeof: Symbol(react.element), type: "option", key: "3", ref: null, props: {…}, …} 3: {$$typeof: Symbol(react.element), type: "option", key: "4", ref: null, props: {…}, …} 长度:4 原型:数组(0) 我想在这里设置:-
<Form.Group>
<Form.Label>Quarters</Form.Label>
<Form.Control as="select" id="quarter">
</Form.Control>
</Form.Group>
【问题讨论】:
-
向我们展示你目前拥有的东西,在这里粘贴一些代码
-
StackOverflow 不是免费的编码服务。请说明您到目前为止所做的尝试。
标签: reactjs