Firebase - Print records in descending order

1

I can not print the records in descending order. I looked at several websites for tips that could help me, but when I adapt to my code, nothing works!

My question is:

I'm creating a game on Intel XDK using Firebase as a database and Javascript to handle them, but I can not display the records in growing order and declining >, which is what I want. Same as a Ranking.

I have the following code:

<html>
<head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale= 1.0, maximum-scale= 1.0, user-scalable=no />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <script src="https://cdn.firebase.com/js/client/1.0.17/firebase.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.css></script>
</head>

<body>
<table>
    <thead>
        <th>NOME</th>
        <th>TEMPO</th>
        <th>ACERTOS</th>
        <th>ERROS</th>
    </thead>
    <tbody id="resultado">

    </tbody>
</table>
<script>
    $(document).ready(function(){
        var APP = new Firebase("https://testestroop-c52df.firebaseio.com/");
        APP.ref().child('jogada').on('child_added', function(snap){
            var jogada = snap.val();
            var tr = document.createElement('tr');
            var td1 = document.createElement('td');
            var td2 = document.createElement('td');
            var td3 = document.createElement('td');
            var td4 = document.createElement('td');

            td1.appendChild(document.createTextNode(jogada.nomeJogador));
            tr.appendChild(td1);
            td2.appendChild(document.createTextNode(jogada.tempo));
            tr.appendChild(td2);
            td3.appendChild(document.createTextNome(jogada.acertos));
            tr.appendChild(td3);
            td4.appendChild(document.createTextNode(jogada.erros));
            tr.appendChild(td4);
            resultado.appendChild(tr);
        }
    });
</script>
</body>
</html>
  

And in this image below is the structure of the database in Firebase:

Thank you very much for your help.

    
asked by anonymous 13.02.2017 / 00:36

1 answer

1

The problem is that there were "loose ends" in the code such as the lack of some ) questions in the jQuery code and you also had a writing error that was in the td3.appendChild(document.createTextNome(jogada.acertos)); line instead of createTextNode .

In% w / o the jQuery library was also not being called correctly and a <head> was missing, it had the " extension instead of .css : .js

  

Here you have an online example working - link

And here is the code your complete code:

<html>
<head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale= 1.0, maximum-scale= 1.0, user-scalable=no />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <!-- <meta charset="UTF-8"> Utiliza isto em vez da linha acima se estás a construir esta plataforma como um projeto recente -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script><scriptsrc="https://cdn.firebase.com/js/client/1.0.17/firebase.js"></script>
</head>

<body>
<table>
    <thead>
        <th>NOME</th>
        <th>TEMPO</th>
        <th>ACERTOS</th>
        <th>ERROS</th>
    </thead>
    <tbody id="resultado">

    </tbody>
</table>

<script>
$(document).ready(function(){
    var APP = new Firebase("https://testestroop-c52df.firebaseio.com/");
    APP.ref().child('jogada').on('child_added', function(snap){
        var jogada = snap.val();
        var tr = document.createElement('tr');
        var td1 = document.createElement('td');
        var td2 = document.createElement('td');
        var td3 = document.createElement('td');
        var td4 = document.createElement('td');

        td1.append(document.createTextNode(jogada.nomeJogador));
        tr.appendChild(td1);
        td2.append(document.createTextNode(jogada.tempo));
        tr.appendChild(td2);
        td3.append(document.createTextNode(jogada.acertos));
        tr.appendChild(td3);
        td4.append(document.createTextNode(jogada.erros));
        tr.appendChild(td4);
        resultado.appendChild(tr);
    });
});
</script>
<body>
</html>
    
13.02.2017 / 04:52