mycode的:
import React, { Component } from "react";
import { View, StyleSheet } from "react-native";
import { Table, Row, Rows} from 'react-native-table-component';
export default class TableReactNative extends Component {
state={
tableHead : ['Head1', 'Head2', 'Head3', 'Head4','Head5','Head6','Head7', 'Head8'],
tableData :[[
'1', '2', '3', '4','1', '2', '3', '4'],[
'1', '2', '3', '4','1', '2', '3', '4']],
rowData:[],
}
componentDidMount(){
this.setTable();
}
setTable(){
var table=[];
for(let i=0;i<this.state.tableData.length;i++){
var tabHead=this.state.tableHead[i];
var tabData=this.state.tableData[i];
var val= <View><Table><Row data={tabHead} /><Rows data={tabData} /></Table></View>;
table.push(val);
}
this.setState({rowData:table})
}
render() {
return (
<View>
{this.state.rowData}
</View>
)
}
}
预期o / p:
Head1 Head2 Head3 ...
1 2 3 ...
Head1 Head2 Head3 ...
1 2 3 ...
Head1 Head2 Head3 ...
1 2 3 ...