Show the last record as first Firebase

1

Hello, I have been learning to work with firebase, which I thought was wonderful, but due to my lack of experience, it is difficult for me to understand their documentation, so I ask for your help.

What I want is that when I show the records of my database in my Web application these are printed from bottom to top that is to say that the last record was shown in my app as the first one and so descending I tried to use 'orderByChild ()' but I have no result, I would also like to know how to sort the records by referring to the value of a node in this case "date", I also tried but I have no results I will leave part of the code to see if they can give me a hand I would be very grateful

const dbNoticias = firebase.database().ref('noticias/').orderByChild('fecha')   
  dbNoticias.on('value', function(snapshot){
    var data= snapshot.val()
    $('#noticias').empty()
    var row=""
    for(noticias in data){
        var contenido= data[noticias].contenidoCorto
        var mostrar= contenido.substring('0', '100')
        row+='<div class="card-style animated fadeInDown">'+
             '<img class="img-card" src="'+data[noticias].url+'">'+
             '<div class="card-body">'+
             '<h3><b>'+data[noticias].titulo+'</b></h3>'+
             '<article>'+mostrar+' ... <a data="'+noticias+'" href="#" class="btnMostrar" >Leer más</a></article>'+
             '</div>'+
             '</div>'
    }
    $('#noticias').append(row)
    var row=""})

thanks ...

    
asked by MOx Designer 07.09.2018 в 21:28
source

1 answer

0

Firebase Database always returns you in ascending order. He can not return you as you want what you could do.

  • Put everything in a list and then on the client side do an inverse () and just do the for of the elements.
  • Use an extra variable of timestamp but that is negative so that it brings you the inverse data and in this way firebase will order everything as you want it.

Greetings.

    
answered by 08.09.2018 в 04:19