Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 多个节点,搜索Firebase数据库_Android_Firebase_Firebase Realtime Database - Fatal编程技术网

Android 多个节点,搜索Firebase数据库

Android 多个节点,搜索Firebase数据库,android,firebase,firebase-realtime-database,Android,Firebase,Firebase Realtime Database,我一直在搜索不同的示例,但无法为我的firebase节点找到合适的解决方案。我有3个节点1用于提问,第二个节点包含问题的答案,第三个节点包含对该答案的评论 如何使用firebase执行查询 我一直在寻找不同的示例,但无法为我的fire基表找到合适的解决方案。我有3个节点 问题 答复 对答复的评论 如何使用firebase执行查询(基于连接的概念实现) 我将如何获得具体问题的答案以及对这些答案的评论 这是我的JSON { "Answer" : { "f4035

我一直在搜索不同的示例,但无法为我的firebase节点找到合适的解决方案。我有3个节点1用于提问,第二个节点包含问题的答案,第三个节点包含对该答案的评论

如何使用firebase执行查询 我一直在寻找不同的示例,但无法为我的fire基表找到合适的解决方案。我有3个节点

  • 问题
  • 答复
  • 对答复的评论
  • 如何使用firebase执行查询(基于连接的概念实现)

    我将如何获得具体问题的答案以及对这些答案的评论

    这是我的JSON

        {
          "Answer" : {
    
            "f40357b1-d1f5-4b7a-98ec-54d9e7b2e518" : {
    
              "dateTime" : "16 Mar 2017 15:30:29",
              "professorAnswer" : "Hezbollah is an Islamist religious organization founded in 1985 and based in Lebanon. It follows Shi'Islam (also called Shi'ite Islam), the second largest denomination of Islam. Shi'a Muslims follow the teachings of the prophet Muhammad, a direct descendant of Isma'il (the first son of Ibrahim/Abraham).Contd.!",
              "professorId" : "7ceef713-eb59-4db4-a8d2-21d5a01eedfc",
              "questionId" : "fd2a34a0-e7d9-4b2c-8192-59705df827c2"
            }
          },
    
          "comment" : {
            "29192e3a-a013-4fcc-9859-1f5cc62464cb" : {
              "commentText" : "ORGANIZATION hezbollah bases on the bible but their goals is to save people in pagans work!",
              "dateTime" : "16 Mar 2017 15:30:52",
     "AnswerId" : "f40357b1-d1f5-4b7a-98ec-54d9e7b2e518"
              "questionId" : "fd2a34a0-e7d9-4b2c-8192-59705df827c2",
              "userId" : "bXCeW6jfidbHuMCCCMkDGWcGZRS2"
            }
          },
    
    
    
     "questions" : {
    
        "41c454a8-fab6-4e41-9093-b1120ffd1be0" : {
          "description" : "I know they're a Islamic organization but where are they based? What are their goals?",
          "idQuestion" : "fd2a34a0-e7d9-4b2c-8192-59705df827c2",
          "time" : "16 Mar 2017 15:30:12",
          "title" : "What are the aims of the religious organization Hezbollah?",
          "user_id" : "bXCeW6jfidbHuMCCCMkDGWcGZRS2",
    
        }
      },
    
    
    
     "user" : {
    
        "13bd37e5-fc87-4468-a89e-7cb4ecaab05f" : {
    
          "email" : "email@gmail.com ",
          "user_id" : "bXCeW6jfidbHuMCCCMkDGWcGZRS2"
        }
    }
    

    问题是我想过滤那些事件。。。例如,使用
    .orderByChild(“Answer”).equalTo(QID)
    可能是错误的查询,但这只是为了让concept只获取给定问题ID的答案,然后用它填充我的列表。

    正确的方法是分别获取每个数据,我不太清楚您的数据是如何组织的,但这可能是一个合适的解决方案:

    // Gets the Question with id = QID
    mdatabaseReference.child("Questions").child(QID);
    
    // Gets the Answers for that question
    mdatabaseReference.child("Answers").child(QID).once("value", function(answers) {
    
        // For every Answer gets the comments
        for(var answerID in answers) mdatabaseReference.child("Comments").child(QID).child(answerID);
    });
    
    编辑:要有效地使用Firebase,您应该根据检索数据的方式来组织数据。如果您想获得给定问题的所有答案,我建议您使用以下数据结构:

    {
        "Answers": {
            "questionID": {
                "answerID": {
                    "dateTime" : "16 Mar 2017 15:30:29",
                    "professorAnswer" : "Hezbollah is an Islamist religious...,
                    "professorID" : "...",
                    "questionID" : "..."
                }
            }
        }
    }
    
    因此,您可以通过以下方式获取给定问题ID的数据:

    mdatabaseReference.child("Answer").child(questionID).once('value', function(answers) {
        // answers contains all the answer for the question with ID == questionID
    });
    

    注意:Firebase中没有表,一切都是JSON对象

    正确的方法是分别获取每个数据,我不太清楚您的数据是如何组织的,但这可能是一个合适的解决方案:

    // Gets the Question with id = QID
    mdatabaseReference.child("Questions").child(QID);
    
    // Gets the Answers for that question
    mdatabaseReference.child("Answers").child(QID).once("value", function(answers) {
    
        // For every Answer gets the comments
        for(var answerID in answers) mdatabaseReference.child("Comments").child(QID).child(answerID);
    });
    
    编辑:要有效地使用Firebase,您应该根据检索数据的方式来组织数据。如果您想获得给定问题的所有答案,我建议您使用以下数据结构:

    {
        "Answers": {
            "questionID": {
                "answerID": {
                    "dateTime" : "16 Mar 2017 15:30:29",
                    "professorAnswer" : "Hezbollah is an Islamist religious...,
                    "professorID" : "...",
                    "questionID" : "..."
                }
            }
        }
    }
    
    因此,您可以通过以下方式获取给定问题ID的数据:

    mdatabaseReference.child("Answer").child(questionID).once('value', function(answers) {
        // answers contains all the answer for the question with ID == questionID
    });
    

    注意:你在Firebase中没有表,一切都是JSON对象

    在Firebase中没有连接的概念。它的noSql..你需要做的就是根据问题Id进行查询,然后在答案Id中检查问题Id..同样的事情是对注释进行嵌套的基于事件的搜索

    fireBase中没有连接的概念。它的noSql..您需要做的就是根据问题Id查询,然后在回答Id中检查问题Id..同样的事情也适用于注释,这将是一个嵌套的基于事件的搜索

    我想问knw是否有加入消防基地的概念。?其中,我只运行一次查询,它会显示特定问题的答案和注释。没有连接的概念,最好单独获取数据片段,并根据您想要检索的方式组织数据。如果你真的想得到答案和评论,你可以把你的评论作为答案的一个子项,但我建议你尝试单独获取数据,这是很好的,也是在Firebase中获取数据的正确方法:)这确实有用,但我不这么认为,如果数据的大小变得巨大,那该怎么办呢。?然后它将加载每个表的数据,然后比较这些数据。这会使我的应用程序变慢。通过这种方法,你只获取你需要的数据。例如,如果你有2000个问题,你只能得到
    id==QID
    的问题。这真的取决于你如何构造你的数据,我用一个好的数据结构的例子更新了我的答案。如果您有更多问题,请告诉我;)告诉我一件事。我想知道有没有加入消防基地的概念。?其中,我只运行一次查询,它会显示特定问题的答案和注释。没有连接的概念,最好单独获取数据片段,并根据您想要检索的方式组织数据。如果你真的想得到答案和评论,你可以把你的评论作为答案的一个子项,但我建议你尝试单独获取数据,这是很好的,也是在Firebase中获取数据的正确方法:)这确实有用,但我不这么认为,如果数据的大小变得巨大,那该怎么办呢。?然后它将加载每个表的数据,然后比较这些数据。这会使我的应用程序变慢。通过这种方法,你只获取你需要的数据。例如,如果你有2000个问题,你只能得到
    id==QID
    的问题。这真的取决于你如何构造你的数据,我用一个好的数据结构的例子更新了我的答案。如果您有更多问题,请告诉我;)告诉我一件事。与其用文字描述您的数据结构,不如共享一段具有代表性的JSON片段。您可以通过在中单击导出JSON来获得此信息。等待您的答复。!@Frank van Puffelenins不必用文字描述您的数据结构,而是共享一个具有代表性的JSON片段。您可以通过在中单击导出JSON来获得此信息。等待您的答复。!@弗兰克·范·帕夫伦