<i id='EKSeR'><tr id='EKSeR'><dt id='EKSeR'><q id='EKSeR'><span id='EKSeR'><b id='EKSeR'><form id='EKSeR'><ins id='EKSeR'></ins><ul id='EKSeR'></ul><sub id='EKSeR'></sub></form><legend id='EKSeR'></legend><bdo id='EKSeR'><pre id='EKSeR'><center id='EKSeR'></center></pre></bdo></b><th id='EKSeR'></th></span></q></dt></tr></i><div id='EKSeR'><tfoot id='EKSeR'></tfoot><dl id='EKSeR'><fieldset id='EKSeR'></fieldset></dl></div>
  • <legend id='EKSeR'><style id='EKSeR'><dir id='EKSeR'><q id='EKSeR'></q></dir></style></legend>

      <tfoot id='EKSeR'></tfoot>
        <bdo id='EKSeR'></bdo><ul id='EKSeR'></ul>
    1. <small id='EKSeR'></small><noframes id='EKSeR'>

      1. 如何遍历从 snapshot.val() 收到的数据并根据键将其推送到数组

        How to loop through the data I receive from snapshot.val() and push it to an array based on keys(如何遍历从 snapshot.val() 收到的数据并根据键将其推送到数组)

      2. <tfoot id='1cUGl'></tfoot>
        1. <small id='1cUGl'></small><noframes id='1cUGl'>

          <legend id='1cUGl'><style id='1cUGl'><dir id='1cUGl'><q id='1cUGl'></q></dir></style></legend>
        2. <i id='1cUGl'><tr id='1cUGl'><dt id='1cUGl'><q id='1cUGl'><span id='1cUGl'><b id='1cUGl'><form id='1cUGl'><ins id='1cUGl'></ins><ul id='1cUGl'></ul><sub id='1cUGl'></sub></form><legend id='1cUGl'></legend><bdo id='1cUGl'><pre id='1cUGl'><center id='1cUGl'></center></pre></bdo></b><th id='1cUGl'></th></span></q></dt></tr></i><div id='1cUGl'><tfoot id='1cUGl'></tfoot><dl id='1cUGl'><fieldset id='1cUGl'></fieldset></dl></div>
            <bdo id='1cUGl'></bdo><ul id='1cUGl'></ul>

                  <tbody id='1cUGl'></tbody>
                • 本文介绍了如何遍历从 snapshot.val() 收到的数据并根据键将其推送到数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想根据用户键循环从 snapshot.val() 收到的数据并将它们推送到数组中.我尝试在 for..in 这样的循环的帮助下做到这一点,

                  I want to loop through the data I receive from snapshot.val() based on user keys and push them into an array. I tried doing it with the help of for..in loop like this,

                  firebase.database().ref('interests').child("I would like to dine with").on('value', (snapshot) => {
                    var data = snapshot.val();
                    if(snapshot.exists()){
                      for(let key in data){
                        console.log("data[key]",data[key]);
                        this.intVal.push(data[key]);
                        console.log("intVal",this.intVal);
                      }
                    }
                  })
                  

                  但我得到了这样的东西,

                  But I'm getting something like this,

                  如果您注意到,我的第一个数组在用户键下包含 1 个对象,而我的第二个数组在其用户键下包含 3 个对象.如何将每个值推送到单独的数组中?

                  If you notice, my first array contains 1 object under a user key and my second array contains 3 objects under their user keys. How can I push every single value in a separate array?

                  任何帮助将不胜感激!谢谢

                  Any help would be much appreciated! Thanks

                  推荐答案

                  有一个 DataSnapshot.forEach() 方法 正是为了这个目的:

                  There is a DataSnapshot.forEach() method precisely for this purpose:

                  firebase.database().ref('interests').child("I would like to dine with").on('value', (snapshot) => {
                    snapshot.forEach((child) => {
                      console.log(child.key, child.val()); 
                      this.intVal.push(child.val());
                      console.log("intVal",this.intVal);
                    });
                    }
                  })
                  

                  这篇关于如何遍历从 snapshot.val() 收到的数据并根据键将其推送到数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                  <i id='XJb2t'><tr id='XJb2t'><dt id='XJb2t'><q id='XJb2t'><span id='XJb2t'><b id='XJb2t'><form id='XJb2t'><ins id='XJb2t'></ins><ul id='XJb2t'></ul><sub id='XJb2t'></sub></form><legend id='XJb2t'></legend><bdo id='XJb2t'><pre id='XJb2t'><center id='XJb2t'></center></pre></bdo></b><th id='XJb2t'></th></span></q></dt></tr></i><div id='XJb2t'><tfoot id='XJb2t'></tfoot><dl id='XJb2t'><fieldset id='XJb2t'></fieldset></dl></div>
                    • <bdo id='XJb2t'></bdo><ul id='XJb2t'></ul>
                        <tbody id='XJb2t'></tbody>

                        • <legend id='XJb2t'><style id='XJb2t'><dir id='XJb2t'><q id='XJb2t'></q></dir></style></legend>

                            <small id='XJb2t'></small><noframes id='XJb2t'>

                          • <tfoot id='XJb2t'></tfoot>