React native listView,将firebase中的2个数据行添加到一行中
如何在列表视图中呈现2个项目? 我正在使用firebase获取数据,我想将两个数据放在一行中 我正在使用此代码添加1项React native listView,将firebase中的2个数据行添加到一行中,react-native,React Native,如何在列表视图中呈现2个项目? 我正在使用firebase获取数据,我想将两个数据放在一行中 我正在使用此代码添加1项 constructor(props) { super(props); this.state = { swipeToClose: true, dataSource: new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 !== row2, }) }; this.items
constructor(props) {
super(props);
this.state = {
swipeToClose: true,
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
})
};
this.itemsRef = this.getRef().child('movies');
}
render() {
return (
<View style={styles.container}>
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderItem.bind(this)}
style={styles.listview}
</View>
);
}
_renderItem(item) {
const onPress = () => {
AlertIOS.prompt(
'Complete',
null,
[
{text: 'Complete', onPress: (text) => this.itemsRef.child(item._key).remove()},
{text: 'Cancel', onPress: (text) => console.log('Cancelled')}
],
'default'
);
};
return (
<View style={styles.rowContainer}>
<TouchableHighlight style={styles.leftContainer} onPress={onPress}>
<View style={styles.viewContainer}>
<Image
defaultSource={require('./noimage.png')}
source={{uri: item.image}}
style={styles.thumbnail}/>
<Text style={styles.title}>{item.title}</Text>
<Text style={styles.year}>{item.year}</Text>
</View>
</TouchableHighlight>
</View>
);
}
}
构造函数(道具){
超级(道具);
此.state={
swipeToClose:没错,
数据源:新建ListView.dataSource({
行已更改:(行1,行2)=>行1!==行2,
})
};
this.itemsRef=this.getRef().child('movies');
}
render(){
返回(
{
AlertIOS.prompt(
"完成",,
无效的
[
{text:'Complete',onPress:(text)=>this.itemsRef.child(item.\u key).remove(),
{text:'Cancel',onPress:(text)=>console.log('Cancelled')}
],
“默认”
);
};
返回(
{item.title}
{项目年份}
);
}
}
我是否应该更改this.state.dataSource或其他内容将您的ListView更新为:
render() {
return (
<View style={styles.container}>
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderItem.bind(this)}
contentContainerStyle={styles.listView}
/>
</View>
);
}
import React, {
StyleSheet,
Dimensions,
} from 'react-native';
var width = Dimensions.get('window').width; //full screen width
var styles = StyleSheet.create({
container: {
...
},
listView: {
flexWrap: 'wrap',//here you are telling the list view to wrap its items next to each others
flexDirection: 'row',
},
rowContainer: {
width:width/2, //here you make row item half width according to screen width
}
});
当你说要将两个数据放在一行中时,你是指两个按钮吗?我的意思是我要从fireBase中读取两行数据,并在列表视图的一行中显示它们每行数据包含:(年份、标题和图像)你知道如何解决这个问题吗?