我在渲染方面遇到问题,因此有人告诉我将用作状态的表设置为可正确更新数据的状态。
我正在使用的表:
<ScrollView horizontal={true} style={{ marginTop: 20 }}>
<View>
<Table borderStyle={{ borderWidth: 1, borderColor: '#C1C0B9' }}>
<Row
data={this.state.tableHead}
widthArr={this.state.widthArr}
style={styles.header}
textStyle={styles.text}
/>
</Table>
<ScrollView style={styles.dataWrapper}>
<Table borderStyle={{ borderWidth: 1, borderColor: '#C1C0B9' }}>
{this.state.tableData.map((rowData, index) => (
<Row
key={index}
data={rowData}
widthArr={this.state.widthArr}
style={[styles.row, index % 2 && { backgroundColor: '#F7F6E7' }]}
textStyle={styles.text}
/>
))
//this.state.myState
}
</Table>
</ScrollView>
</View>
</ScrollView>
它在render()
下工作,我尝试制作一个setState
onPress
选项来激活它,我做了类似的事情:
updateState = () =>
this.setState({
myState: this.state.tableData.map((rowData, index) => (
<Row
key={index}
data={rowData}
widthArr={this.state.widthArr}
style={[styles.row, index % 2 && { backgroundColor: '#F7F6E7' }]}
textStyle={styles.text}
/>
)),
})
但是无法正常工作。
添加toggle
状态。此状态将在每个onPress
事件上更改。
((对于下面的示例,我正在使用onClick
)