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.info(optionTemplate2);
}
я получаю данные в optionTemplate2, но я не могу установить в select
0: {$$typeof: Symbol(react.element), тип: «option», ключ: «1», ссылка: null, реквизиты: {…}, …} 1: {$$typeof: Symbol(react.element), тип: «опция», ключ: «2», ссылка: null, реквизиты: {…}, …} 2: {$$typeof: Symbol(react.element), тип: «опция», ключ: «3», ссылка: null, реквизиты: {…}, …} 3: {$$typeof: Symbol(react.element), тип: «опция», ключ: «4», ссылка: null, реквизиты: {…}, …} длина: 4 прото: Массив (0) я хочу установить его здесь: -
<Form.Group>
<Form.Label>Quarters</Form.Label>
<Form.Control as = "select" id = "quarter">
</Form.Control>
</Form.Group>
StackOverflow не является бесплатной службой кодирования. Пожалуйста, объясните, что вы пробовали до сих пор.
class FirstComponent extends React.Component{
constructor(props){
super(props);
let todayDate = new Date();
this.state = {
finsclYear: [
{ name: '2014-2015', id: "2014-03-31"},
{ name: '2016-2017', id: "2016-03-31" },
{ name: '2017-2018', id: "2017-03-31" },
{ name: '2018-2019', id: "2018-03-31" },
{ name: '2019-2020', id: todayDate}
],
quarter:[ ],
chartData:chartData[0],
tableData: FilterTableCustom
};
this.setQuarterData=this.setQuarterData.bind(this);
this.changeData=this.changeData.bind(this);
}
setQuarterData(el){
let value=el.target.value;
let quarter;
let today = new Date(value);
let month=today.getMonth();
//calculating quarter for financial year
if (month<12 && month>2){
quarter = Math.floor(month / 3);
}
else{
quarter = Math.floor((month+12) / 3);
}
let list2=document.getElementById("quarter");
switch(quarter){
case 1:
this.setState({
quarter:[{ name: 'Q1', id: 1 } ]
});
break;
case 2:
this.setState({
quarter:[{ name: 'Q1', id: 1 },
{ name: 'Q2', id: 2 } ]
});
break;
case 3:
this.setState({
quarter:[{ name: 'Q1', id: 1 },
{ name: 'Q2', id: 2 },
{ name: 'Q3', id: 3 }]
});
break;
case 4:
this.setState({
quarter:[{ name: 'Q1', id: 1 },
{ name: 'Q2', id: 2 },
{ name: 'Q3', id: 3 },
{ name: 'Q4', id: 4 }]
});
break;
default :
null
}
}
changeData(){
this.setState({
chartData:chartData2[0],
tableData: FilterTableCustom2
});
}
render(){
const {tableData}=this.state;
const {chartData}=this.state;
console.info(tableData);
const {quarter} =this.state;
let finsclYearData = this.state.finsclYear.map(v => (
<option value = {v.id} key = {v.id}>{v.name}</option>
));
let quarterData = "";
if (quarter.length!=0){
quarterData =quarter.map(v => (
<option value = {v.id} key = {v.id}>{v.name}</option>
));
}
покажите нам, что у вас есть, вставьте сюда код