I am working on an application on "React-native". I read many manuals, but I did not find a solution to my problem. I just need to display the data from the firebase in the Listview table, but the keys to it are in a parallel node. Here is an example of the structure:
I need to make the first request to get the keys, and the next to get and display the data in the listview.
At the moment, everything looks like this:
should be so
I know that the data is requested by the componentDidMount () function and is called once. I have a complete stupor, I killed a few days and did not find a solution. Can someone tell you the right solution or help edit the code to get the desired result?
Here is my implementation, but I only get data from the "costumers" for it:
constructor(props) { super(props); var userId = firebase.auth().currentUser.uid; this.ref = firebase.database().ref('/customers/' + userId); const myDataSource = new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 !== row2, }); this.state = { dataSource: myDataSource }; } readData(ref) { ref.on('value', (dataSnapshot) => { var tasks = []; dataSnapshot.forEach((child) => { tasks.push({ name: child.val(), _key: child.key }); }); this.setState({ dataSource: this.state.dataSource.cloneWithRows(tasks) }); }); }
componentDidMount() { this.readData(this.ref); } renderRow(rowData){ return ( <TouchableHighlight onPress={()=>this.pressRow(rowData)} underlayColor = '#dddddd'> <View style ={styles.row}> <Image source={require('./test_image.png')} style={styles.deviceImage} /> <View style={styles.rightContainer}> <Text style={styles.name}>Name: {rowData.name}</Text> <Text style={styles.ip}>IP: {rowData.name}</Text> <Text style={styles.user}>User: {rowData.name}</Text> </View> </View> </TouchableHighlight> ) } render() { return ( <View style={styles.backgroundMainScreen}> <Image style={styles.header} source={require('./test_avatar.png')} blurRadius={10}> </Image> <Image style={styles.avatar} source={require('./test_avatar.png')}> </Image> <View style={styles.listView}> <Text style={styles.nameUser}>Bill West</Text> <Text style={styles.street}>187 west street</Text> <Text style={styles.city}>New York, NY 10003</Text> <Text style={styles.bottomText}>last sync</Text> <ListView dataSource = {this.state.dataSource} renderRow = {this.renderRow.bind(this)}> </ListView> </View> </View> ) }



