Reputation: 191
This code is working fine but I must change a state to show it on the table I'm using.
The code is:
this.state.tableData=[]
for (let i = 0; i < this.state.cityTable.length; i += 1) {
let rowData = [];
for (let j = 0; j < 7; j += 1) {
switch (j) {
case 0: //draw cities rows
rowData.push(this.state.cityTable[i])
break;
case 1: //num of candidate total
this.dbRef.where('Destination', '==', this.state.delegation)
.where('Location', '==', this.state.cityTable[i])
.get()
.then(querySnapshot => {
rowData.push(querySnapshot.size)
});
break;
case 2: //num of candidate
this.dbRef.where('Destination', '==', this.state.delegation)
.where('Location', '==', this.state.cityTable[i])
.get()
.then(querySnapshot => {
rowData.push(querySnapshot.size)
});
break;
}
}
this.state.tableData.push(rowData);
}
It is working but I know I must put some setState or make some force render. I call this method on render inside OnPress button - it has a picker to change values so can generate reports to that.
Upvotes: 1
Views: 47
Reputation: 778
I guess this is what you need if you want to replace the items in tableData:
this.setState({tableData: rowData})
If you want to append to the items in tableData,
this.setState({tableData: [...this.state.tableData, ...rowData})
Upvotes: 1