Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.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
Database 使用AngularFire2查询集合_Database_Angular_Firebase_Ionic2_Angularfire2 - Fatal编程技术网

Database 使用AngularFire2查询集合

Database 使用AngularFire2查询集合,database,angular,firebase,ionic2,angularfire2,Database,Angular,Firebase,Ionic2,Angularfire2,我正在使用AngularFire 2构建一个离子2应用程序,以与Firebase通信 这是我的Firebase数据库: { "films" : [ { "title" : "John Wick", "summary": "Ex-assassin John Wick takes down the Russian Mafia after being violenty attacked by Russian thugs i

我正在使用AngularFire 2构建一个离子2应用程序,以与Firebase通信

这是我的Firebase数据库:

    {
    "films" : [
        {
            "title" : "John Wick",
            "summary": "Ex-assassin John Wick takes down the Russian Mafia after being violenty attacked by Russian thugs in his home after the death of his wife",
            "date" : "2014",
            "duration": "97 minutes",
            "rating": "15",
            "cover" : "none",
            "actors" : {
                "keanureeves" : true,
                "willemdafoe" : true,
                "michaelnyqvist" : true,
                "ianmcshane" : true,
                "johnleguizamo" : true,
                "bridgetmoynahan" : true,
                "alfieallen" : true,
                "adriannepalicki" : true
            },
            "genres" : {
                "action" : true,
                "thriller" : true
            },
            "images" : {
               "image1" : true,
               "image2" : true,
               "image3" : true,
               "image4" : true,
               "image5" : true
            }
        },
        {
            "title" : "Gladiator",
            "summary": "The general who became a slave, the slave who became a gladiator, the gladiator who defied an empire",
            "date" : "2000",
            "duration": "2hr 29 minutes",
            "rating": "15",
            "cover" : "none",
            "actors" : {
                "russellcrowe" : true,
                "oliverreed" : true
            },
            "genres" : {
                "action" : true
            },
            "images" : {
               "image6" : true
            }
        },
        {
            "title" : "Catch me if you can",
            "summary": "Frank Abagnale Jr, master of deception",
            "date" : "2002",
            "duration": "135 minutes",
            "rating": "12",
            "cover" : "none",
            "actors" : {
                "tomhanks" : true,
                "leonardodicaprio" : true,
                "christopherwalken" : true
            },
            "genres" : {
                "comedy" : true,
                "thriller" : true
            },
            "images" : {
               "image7" : true,
               "image8" : true
            }
        },
        {
            "title" : "Street Kings",
            "summary": "Corrupt, murderous cops in Los Angeles",
            "date" : "2008",
            "duration": "104 minutes",
            "rating": "15",
            "cover" : "none",
            "actors" : {
                "forestwhitaker" : true,
                "keanureeves" : true,
                "chrisevans" : true
            },
            "genres" : {
                "crime" : true,
                "action" : true,
                "thriller" : true
            },
            "images" : {
               "image9" : true
            }
        }
    ],


    "images" : {
      "image1" : {
         "image" : "ref",
         "caption": "Keanu Reeves as John Wick"
      },
      "image2" : {
         "image" : "ref",
         "caption": "Taking down the Russian mafia"
      },
      "image3" : {
         "image" : "ref",
         "caption": "Nightclub scene #1"
      },
      "image4" : {
         "image" : "ref",
         "caption": "Nightclub scene #2"
      },
      "image5" : {
         "image" : "ref",
         "caption": "Nightclub scene #3"
      },
      "image6" : {
         "image" : "ref",
         "caption": "Maximus the Gladiator"
      },
      "image7" : {
         "image" : "ref",
         "caption": "Leonardo DiCaprio as Frank Abagnale Jr"
      },
      "image8" : {
         "image" : "ref",
         "caption": "Panam-Air hostesses"
      },
      "image9" : {
         "image" : "ref",
         "caption": "Keanu reeves as Detective Tom Ludlow"
      }
    },


    "actors" : {
        "keanureeves" : {
           "name" : "Keanu reeves",
           "nationality" : "Canadian"
        },
        "willemdafoe" : {
           "name" : "Willem Dafoe",
           "nationality" : "Dutch"
        },
        "michaelnyqvist" :  {
           "name" : "Michael Nyqvist",
           "nationality" : "Swedish"
        },
        "ianmcshane" : {
           "name" : "Ian McShane",
           "nationality" : "English"
        },
        "johnleguizamo" : {
           "name" : "John Leguizamo",
           "nationality" : "Colombian-American"
        },
        "bridgetmoynahan" : {
           "name" : "Bridget Moynahan",
           "nationality" : "American"
        },
        "alfieallen" : {
           "name" : "Alfie Allen",
           "nationality" : "English"
        },
        "adiannepalicki" : {
           "name" : "Adrianne Palicki",
           "nationality" : "American"
        },
        "russellcrowe" : {
           "name" : "Russell Crowe",
           "nationality" : "New Zealander"
        },
        "oliverreed" : {
           "name" : "Oliver Reed",
           "nationality" : "English"
        },
        "leonardodicaprio" : {
           "name" : "Leonardo DiCaprio",
           "nationality" : "American"
        },
        "tomhanks" : {
           "name" : "Tom Hanks",
           "nationality" : "American"
        },
        "christopherwalken" : {
           "name" : "Christopher Walken",
           "nationality" : "American"
        },
        "martinsheen" : {
           "name" : "Martin Sheen",
           "nationality" : "American"
        },
        "forestwhitaker" : {
           "name" : "Forest Whitaker",
           "nationality" : "American"
        },
        "chrisevans" : {
           "name" : "Chris Evans",
           "nationality" : "American"
        }
    },

    "genres" : {
        "action" : {
            "title": "Action/Adventure"
        },
        "fantasy" : {
            "title": "Fantasy"
        },
        "horror" : {
            "title": "Horror"
        },
        "comedy" : {
            "title": "Comedy"
        },
        "thriller" : {
            "title": "Thriller"
        },
        "sciencefiction" : {
            "title": "Science Fiction"
        },
        "war" : {
            "title": "War"
        },
        "crime" : {
            "title": "Crime"
        },
        "documentary" : {
            "title": "Documentary"
        }      
    }
}
我已将数据反规范化为特定集合,以避免冗余/重复等(根据Firebase的最佳实践建议)

请忽略图像集合中的ref值,因为这些值目前仅作为占位符:)

这是我的home.ts文件:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AngularFire, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
   public movies : FirebaseListObservable<any[]>;

   constructor(public navCtrl  : NavController,
               public angFire  : AngularFire) 
   {

      this.movies = angFire.database.list('/movies/films');
   }
}
要通过提供的键从actors集合检索匹配数据,请执行以下操作:

"actors" : {
   "keanureeves" : true,
   "willemdafoe" : true,
   "michaelnyqvist" : true,
   "ianmcshane" : true,
   "johnleguizamo" : true,
   "bridgetmoynahan" : true,
   "alfieallen" : true,
   "adriannepalicki" : true
},
"actors" : {
   "keanureeves" : {
      "name" : "Keanu reeves",
      "nationality" : "Canadian"
   },
   "willemdafoe" : {
      "name" : "Willem Dafoe",
      "nationality" : "Dutch"
   },
   "michaelnyqvist" :  {
      "name" : "Michael Nyqvist",
      "nationality" : "Swedish"
   },
   "ianmcshane" : {
      "name" : "Ian McShane",
      "nationality" : "English"
   },
   "johnleguizamo" : {
      "name" : "John Leguizamo",
      "nationality" : "Colombian-American"
   },
   "bridgetmoynahan" : {
      "name" : "Bridget Moynahan",
      "nationality" : "American"
   },
   "alfieallen" : {
      "name" : "Alfie Allen",
      "nationality" : "English"
   },
   "adiannepalicki" : {
      "name" : "Adrianne Palicki",
      "nationality" : "American"
   }
}
这有意义吗

我在想我该如何做到这一点

在过去的几个小时里,我一直在互联网上搜索,但我尝试的一切都没有奏效

我可以查询单个集合,但本质上,我想做一个关系查询,使用电影集合中的索引从演员、流派和图像集合中检索匹配的记录


有没有一种方法可以使用AngularFire 2根据特定的键从不同的集合中检索数据,并在一次呼叫中返回这些数据?

简短的回答是否定的。。。我建议看一下简短的答案是否定的。。。我建议你看看
"actors" : {
   "keanureeves" : {
      "name" : "Keanu reeves",
      "nationality" : "Canadian"
   },
   "willemdafoe" : {
      "name" : "Willem Dafoe",
      "nationality" : "Dutch"
   },
   "michaelnyqvist" :  {
      "name" : "Michael Nyqvist",
      "nationality" : "Swedish"
   },
   "ianmcshane" : {
      "name" : "Ian McShane",
      "nationality" : "English"
   },
   "johnleguizamo" : {
      "name" : "John Leguizamo",
      "nationality" : "Colombian-American"
   },
   "bridgetmoynahan" : {
      "name" : "Bridget Moynahan",
      "nationality" : "American"
   },
   "alfieallen" : {
      "name" : "Alfie Allen",
      "nationality" : "English"
   },
   "adiannepalicki" : {
      "name" : "Adrianne Palicki",
      "nationality" : "American"
   }
}