How to return function value inside a firebase call?

0

I'm doing an html page that lists the issues logged in the firebase. If you can help me how do I get the function "getOpc" to return "listing"

Firebase:

- LGf4NE9IRvQlT089uQR
--item: \ "Default select 2 \"
--options
--0: \ "Paris \"
--1: \ "Warsaw \
--3: \ "Rome \"
--2res: \ "Havana \"
- query: \ "< h3> \ "
--type: \" radio \ "

(...)

//listando todas as questoes no banco de dados
firebase.database().ref('/questoes/').once("value").then(function(child) {
    child.forEach(function (d) {
    firebase.database().ref('/questoes/'+d.key).once("value").then(function(dados) {

    var div = document.createElement('div');
    div.innerHTML = (
        '<div class="col-lg-12 shadow" style="padding:30px;"><div class="text-right"><small>'+dados.key+'</small></div>'+
        '<div class="text-left">'+dados.val().pergunta+'</div><ol style="list-style-type:lower-latin;">'+pegarOpc(dados.key)+'</ol></div>'
        );
    conteudo.appendChild(div);
})})})

//função criando lista de opções
function pegarOpc(params) {
    var itemsProcessed = 0;
    var listando = '';
    firebase.database().ref('/questoes/'+params+'/opcoes/').once("value", function(child) {
    child.forEach(function (d) {
    firebase.database().ref('/questoes/'+params+'/opcoes/'+d.key).once("value", function(dados) {

       //criando lista de questoes
        listando += '<li>'+dados.val()+'</li>';
        itemsProcessed++;

        //retornando lista completa
        if(itemsProcessed == child.numChildren()) {
            //console.log(listando);
            return listando;
        }else{}
    })
    })
    })
}
<div class="container">
  <div class="row">
    <div id="conteudo"></div>
  </div>
</div>
    
asked by anonymous 25.07.2018 / 23:16

0 answers