React native 反应本机表组件

React native 反应本机表组件,react-native,react-native-table-component,React Native,React Native Table Component,我正在使用React原生表组件,使用下面的示例。我想将一列的文本向左对齐,其他列的文本居中对齐。问题似乎是,我只能在所有列中普遍设置,而不是单独设置 import React, { Component } from 'react'; import { StyleSheet, View } from 'react-native'; import { Table, TableWrapper, Row, Rows, Col } from 'react-native-table-component';

我正在使用React原生表组件,使用下面的示例。我想将一列的文本向左对齐,其他列的文本居中对齐。问题似乎是,我只能在所有列中普遍设置,而不是单独设置

import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import { Table, TableWrapper, Row, Rows, Col } from 'react-native-table-component';
 
export default class ExampleTwo extends Component {
  constructor(props) {
    super(props);
    this.state = {
      tableHead: ['', 'Head1', 'Head2', 'Head3'],
      tableTitle: ['Title', 'Title2', 'Title3', 'Title4'],
      tableData: [
        ['1', '2', '3'],
        ['a', 'b', 'c'],
        ['1', '2', '3'],
        ['a', 'b', 'c']
      ]
    }
  }
 
  render() {
    const state = this.state;
    return (
      <View style={styles.container}>
        <Table borderStyle={{borderWidth: 1}}>
          <Row data={state.tableHead} flexArr={[1, 2, 1, 1]} style={styles.head} textStyle={styles.text}/>
          <TableWrapper style={styles.wrapper}>
            <Col data={state.tableTitle} style={styles.title} heightArr={[28,28]} textStyle={styles.text}/>
            <Rows data={state.tableData} flexArr={[2, 1, 1]} style={styles.row} textStyle={styles.text}/>
          </TableWrapper>
        </Table>
      </View>
    )
  }
}
 
const styles = StyleSheet.create({
  container: { flex: 1, padding: 16, paddingTop: 30, backgroundColor: '#fff' },
  head: {  height: 40,  backgroundColor: '#f1f8ff'  },
  wrapper: { flexDirection: 'row' },
  title: { flex: 1, backgroundColor: '#f6f8fa' },
  row: {  height: 28  },
  text: { textAlign: 'center' }
});
import React,{Component}来自'React';
从“react native”导入{StyleSheet,View};
从“react native Table component”导入{Table,TableWrapper,Row,Rows,Col};
导出默认类示例两个扩展组件{
建造师(道具){
超级(道具);
此.state={
表格标题:['',标题1',标题2',标题3'],
表格标题:['Title','Title2','Title3','Title4'],
表格数据:[
['1', '2', '3'],
[a',b',c'],
['1', '2', '3'],
['a','b','c']
]
}
}
render(){
const state=this.state;
返回(
)
}
}
const styles=StyleSheet.create({
容器:{flex:1,padding:16,paddingTop:30,backgroundColor:'#fff'},
头部:{高度:40,背景颜色:'#f1f8ff'},
包装器:{flexDirection:'row'},
标题:{flex:1,背景色:'#f6f8fa'},
行:{高度:28},
文本:{textAlign:'中心'}
});

我想你可以这样做:

函数leftAlign(值){
返回(
{value}
);
}
导出默认类示例两个扩展组件{
建造师(道具){
超级(道具);
此.state={
表格标题:['',标题1',标题2',标题3'],
表格标题:['Title','Title2','Title3','Title4'],
表格数据:[
[左对齐('1'),'2','3'],
[左对齐('a'),'b','c'],
[左对齐('1'),'2','3'],
[左对齐('a'),'b','c'],
],
};
}
[...]