在ListView中显示包含3列的标题
Display header containing 3 columns in ListView
我对原生react完全陌生,正在创建一个需要在ListView中显示项目的应用程序。我的ListView由3列组成,即author、title和price,即ListView中的每一行都显示这三列。目前,我只能在标题部分和内容部分显示一列作为
_renderRow(rowData){
return (
<View>
<Text style={styles.row}> {rowData.title}</Text>
</View>
)
},
_renderHeader(){
return (
<View style={styles.sectionDivider}>
<Text style={styles.headingText}>
Title
</Text>
</View>
)
},
我的渲染函数是
render() {
return(
<View style={styles.container}>
<ActivityIndicatorIOS
animating={this.state.isLoading}
size="large">
</ActivityIndicatorIOS>
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderRow}
renderHeader={this._renderHeader}
/>
</View>
)
}
所以,我想在标题和内容部分呈现3列。我在谷歌上搜索了一下,但找不到任何相关内容。
使用flexbox样式的属性可以轻松创建列。例如:
_renderRow(rowData){
return(
<View styles={styles.flexRow}>
<Text>{rowData.title}</Text>
<Text>{rowData.author}</Text>
<Text>{rowData.price}</Text>
</View>
)
_renderHeader() {
return(
<View styles={styles.flexRow}>
<Text>Title</Text>
<Text>Author</Text>
<Text>Price</Text>
</View>
)
}
var styles = StyleSheet.create({
flexRow: {
flex: 1,
flexDirection: 'row' <---- This is the important style property
},
})
我在创建了一个片段https://rnplay.org/apps/p5hzcg如果你想用一个工作的例子。
您应该尝试用之类的东西修改代码
_renderRow(rowData){
return (
<View>
<Text style={styles.column1}> {rowData.text1}</Text>
<View style={styles.sectionDivider}>
<Text style={styles.column2}> {rowData.text2}</Text>
<View style={styles.sectionDivider}>
<Text style={styles.column3}> {rowData.text3}</Text>
</View>
)
},
_renderHeader(){
return (
<View>
<Text style={styles.column1}>textColumm1</Text>
<View style={styles.sectionDivider}>
<Text style={styles.column2}>textColumm2</Text>
<View style={styles.sectionDivider}>
<Text style={styles.column3}>textColumm2</Text>
</View>
)
},
通过这种方式,每行将有3个具有相同样式的元素,如果您固定它们的宽度,它将与列完全相同。嵌入文本可能会改变宽度值,因此您必须决定如果文本太长该怎么办。所以主要是决定是调整文本大小还是多行。
- 如何动态更改dataTablejQuery插件的列标题
- ExtJS 4-自定义排序函数只在点击列标题后执行
- UI网格AngularJS-如何更新UI网格中的列标题
- 页面加载后,将FooTable断点应用于网格视图中的列标题
- 木偶骨干 如何制作带有动态行和列标题的网格表
- 多列标题iggrid与淘汰问题
- JavaScript:从表配置字符串中提取列标题
- SlickGrid:如何查看列标题中的全文
- 如何在dgrid中设置列内容的样式,而不设置列标题的样式
- 在具有行标题和列标题的表中,给定列标题文本和单元格文本,如何选择单元格(td)
- 如何在 ag-grid 中增加列标题的高度
- 手控表未加载动态创建的列标题
- 从 ui-grid 中的可展开行中删除列标题
- 按所有列标题排序
- 通过单击列标题对表进行排序
- 剑道网格列标题
- ExtJS 6 网格无法正确更新/刷新列标题
- jquery 数据表排序 表标题中的单击事件不在列标题文本中
- ExtJs :一个列标题用于多个列
- 如何防止数据表更新列标题文本