I am getting all my users' service records and showing them, but I would like to define the order in which they should be displayed. For this I added a new field with the name Order
. My topic is that I have not been able to find the ordering solution.
Deputy code:
Obtaining data from the database of firebase.
**static getAllServices(callback){
let pathName = "/user/"
firebase.database().ref(pathName).on('value', (snapshot) => {
console.log(snapshot.val())
let data = snapshot.val()
let arrayOfServices = []
if(data){
for(let key in data){
let obj = data[key]
let name = obj.details.name
let photo = obj.details.url
let latitude = obj.details.latitude
let longitude = obj.details.longitude
let identificador = obj.details.id
for(let prop in obj){
let services = obj[prop]
for(let sv in services){
if(services[sv].description && services[sv].rubro && services[sv].title && services[sv].image){
arrayOfServices.push({
userIdent: identificador,
userName: name,
userPhoto: photo,
userLatitude: latitude,
userLongitude: longitude,
userOrder: services[sv].order,
stateOffer: services[sv].stateOffer,
title: services[sv].title,
description: services[sv].description,
rubro: services[sv].rubro,
image: services[sv].image
})
}
}
}
}
}
callback(arrayOfServices)
})
}**
Call to the function I have inserted records in the list:
componentWillMount(){
try{
let user = firebase.auth().currentUser
this.setState({
uid: user.uid,
})
Helpers.getAllServices((services) => {
if(services){
this.setState({
dataSource: this.state.dataSource.cloneWithRows(services),
rawServices: services
})
}
})
}catch(error){
console.log(error)
}
}
Firebase info: