Remove rows in HTML table

0

I have 4 element. The loop does well to only put the attributes of those with the value of name == alex. But I'm loading the rows and columns and I do not want them to come out.

Thanks

<script>
    var tblusuario = document.getElementById('tbl_usuario_list');
    var databaseRef = firebase.database().ref('Usuarios/');
    //var databaseRef = FirebaseFirestore.database().ref('/users');
    var rowindex = 1;

    databaseRef.once('value', function(snapshot) {
        snapshot.forEach(function(childSnapshot) {

            var childKey = childSnapshot.key;
            var childData = childSnapshot.val();

            var row = tblusuario.insertRow(rowindex);
            var cellId = row.insertCell(0);
            var cellNombre = row.insertCell(1);
            var cellenlace = row.insertCell(2);

            if(childData.usuario=="alex"){

                cellId.appendChild(document.createTextNode(childKey));
                cellNombre.appendChild(document.createTextNode(childData.usuario));

                var strMensaje = 'Pulsa para ver la foto';
                var urlFirebase = childData.foto_url;
                var urlFinal= strMensaje.link(urlFirebase);       
                cellenlace.innerHTML=urlFinal;

                rowindex = rowindex + 1;
            }

        });
    });
    function reload_page() {
        window.location.reload();
    }
</script>

    
asked by Vidal 25.11.2017 в 16:04
source

1 answer

0

what happens if: it puts the if () right next to the foreach? so:

<script>
    var tblusuario = document.getElementById('tbl_usuario_list');
    var databaseRef = firebase.database().ref('Usuarios/');
    //var databaseRef = FirebaseFirestore.database().ref('/users');
    var rowindex = 1;

    databaseRef.once('value', function(snapshot) {
        snapshot.forEach(function(childSnapshot) {
            //usar === para comparación
            if(childData.usuario === "alex"){
                var childKey = childSnapshot.key;
                var childData = childSnapshot.val();

                var row = tblusuario.insertRow(rowindex);
                var cellId = row.insertCell(0);
                var cellNombre = row.insertCell(1);
                var cellenlace = row.insertCell(2);

                cellId.appendChild(document.createTextNode(childKey));
                cellNombre.appendChild(document.createTextNode(childData.usuario));

                var strMensaje = 'Pulsa para ver la foto';
                var urlFirebase = childData.foto_url;
                var urlFinal= strMensaje.link(urlFirebase);       
                cellenlace.innerHTML=urlFinal;

                rowindex = rowindex + 1;
            }

        });
    });
    function reload_page() {
        window.location.reload();
    }
</script>
    
answered by 25.11.2017 в 17:27