Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
How to iterate through nested subcollections in flutter web?

I have a set of merchants and each merchant has a document and then a collection, each with nested documents and subcollections.

I created a loop so that every time the user clicks on the div, the function is called to get a snapshot of the next collection in the database.

But the function isn't calling because I'm trying to store the value of each document and collection in an array and then calling that array in the function to link the database to the web app (if that makes any sense).

But it's throwing an error of Uncaught TypeError: Cannot read properties of undefined (reading 'onSnapshot'). Any ideas on how to call the next document and subcollection in the database?

The output from the console.log for the join is: 'doc(Building Materials).collection(Building Materials)'

But the output from the console.log for the ref is: 'undefined'

Here is the code:


 $(".outer-body").click(function(){

  var src = $(this).text().trim();
      sourceArray.push(src);

      var doc;
      var collection;

      var dataArray = [];

      for (var x = 0; x < sourceArray.length; x++){
          var sourceX = sourceArray[x];
          if(sourceArray[x] == sourceArray[0]){
            doc = "doc(" + sourceX + ")";
          } else {
            doc = ".doc(" + sourceX + ")";
          }
          collection = ".collection(" + sourceX + ")";
          dataArray.push(doc + collection);
      }

      var join = dataArray.join('');
      console.log(join);

      const ref = db.collection("all_merchants").doc(customClaim).collection(customClaim).join

      console.log(ref);


      ref.onSnapshot((querySnapshot) => {
        console.log(doc.id, '=>', doc.data());
    });

 }

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To make a document reference dynamic, you must update the function's argument.

'function(argument)' could probably not work as expected. This, on the other hand, will be: function('argument'). It's important to remember that these are functions, not strings.

The API surface of QueryDocumentSnapshot is identical to that of DocumentSnapshot. The exists() method will always return true, and getData() will never return null, because query results contain only existing documents.

I recommend using querySnapshot.exists() to see if the document you're looking for is actually there. That way, you'll be able to deal with any errors more effectively.

Remember to validate that the current version is V9, since this will make it easier to support you in the future.

Including a link of How to Avoid Getting "Cannot read property of undefined" in JavaScript that could also help.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda