Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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
Angular2 Firebase数据分组_Angular_Typescript_Firebase_Firebase Realtime Database_Angularfire - Fatal编程技术网

Angular2 Firebase数据分组

Angular2 Firebase数据分组,angular,typescript,firebase,firebase-realtime-database,angularfire,Angular,Typescript,Firebase,Firebase Realtime Database,Angularfire,我希望有一个重复的数据,每个新组都有一个标题。我的数据模型非常简单 { "-K_kNx9_F2-eTul8548y": { "title": "Registration", "startTime": "2017-02-04T08:00-06:00" }, "-K_kQhBAJFTYEEqaXDp_": { "room": "Cafeteria", "startTime": "2017-02-04T12:00-06:00", "title": "

我希望有一个重复的数据,每个新组都有一个标题。我的数据模型非常简单

{
  "-K_kNx9_F2-eTul8548y": {
    "title": "Registration",
    "startTime": "2017-02-04T08:00-06:00"
  },
  "-K_kQhBAJFTYEEqaXDp_": {
    "room": "Cafeteria",
    "startTime": "2017-02-04T12:00-06:00",
    "title": "Lunch",
    "track": "all"
  },
  ...
}
我很想有一个像

<div *ngFor="**magic happens**">
  <h2>{{time.label}}</h2>
  <div *ngFor="let session of schedule | async">
    {{session.title}}
  </div>
</div>

您可以修改实现,每次执行单独的查询,方法如下:

import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';

export class ScheduleComponent {

    times;
    timesWithSchedules;

    constructor(public af: AngularFire) {

        // A list of times, as per your the code in your question:

        this.times = af.database.list(PATH + '/scheduletimes');

        // Compose an observable that adds the schedule for each time. Each
        // emitted value will be an array of time entries. Enumerate the array
        // and add an observable for the time's schedule:

        this.timesWithSchedules = this.times.do(times => times.forEach(time => {

            time.schedule = af.database

                // Query the schedule entries that correspond the time:

                .list(PATH + '/schedule', {
                    query: {
                        orderByChild: 'startTime'
                        startAt: time.time,
                        endAt: time.time
                    }
                })

                // Sort the emmitted array of sessions by title:

                .map(schedule => schedule.sort(compareTitles));

                function compareTitles(a, b) {
                    if (a.title < b.title) {
                        return -1;
                    }
                    if (a.title > b.title) {
                        return 1;
                    }
                    return 0;
                }
        }));
    }
}
<div *ngFor="let time of timesWithSchedules | async">
  <h2>{{time.label}}</h2>
  <div *ngFor="let session of time.schedule | async">
    {{session.title}}
  </div>
</div>
导入'rxjs/add/operator/do';
导入'rxjs/add/operator/map';
导出类ScheduleComponent{
时代;
时间表;
建造商(公共af:AngularFire){
//根据您的问题代码列出的时间列表:
this.times=af.database.list(PATH+'/scheduletimes');
//编写一个可观察的表格,为每一次添加时间表
//发出的值将是一个时间项数组。枚举该数组
//并为时间计划添加一个可观察的:
this.timesWithSchedules=this.times.do(times=>times.forEach(time=>{
time.schedule=af.database
//查询与时间对应的计划条目:
.列表(路径+“/计划”{
查询:{
orderByChild:“开始时间”
时间,时间,
endAt:time.time
}
})
//按标题对emmitted会话数组进行排序:
.map(schedule=>schedule.sort(compareTiles));
函数比较(a、b){
如果(a.标题b.标题){
返回1;
}
返回0;
}
}));
}
}
然后,您的模板将如下所示:

import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';

export class ScheduleComponent {

    times;
    timesWithSchedules;

    constructor(public af: AngularFire) {

        // A list of times, as per your the code in your question:

        this.times = af.database.list(PATH + '/scheduletimes');

        // Compose an observable that adds the schedule for each time. Each
        // emitted value will be an array of time entries. Enumerate the array
        // and add an observable for the time's schedule:

        this.timesWithSchedules = this.times.do(times => times.forEach(time => {

            time.schedule = af.database

                // Query the schedule entries that correspond the time:

                .list(PATH + '/schedule', {
                    query: {
                        orderByChild: 'startTime'
                        startAt: time.time,
                        endAt: time.time
                    }
                })

                // Sort the emmitted array of sessions by title:

                .map(schedule => schedule.sort(compareTitles));

                function compareTitles(a, b) {
                    if (a.title < b.title) {
                        return -1;
                    }
                    if (a.title > b.title) {
                        return 1;
                    }
                    return 0;
                }
        }));
    }
}
<div *ngFor="let time of timesWithSchedules | async">
  <h2>{{time.label}}</h2>
  <div *ngFor="let session of time.schedule | async">
    {{session.title}}
  </div>
</div>

{{time.label}
{{session.title}

您可以修改实现,每次执行单独的查询,方法如下:

import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';

export class ScheduleComponent {

    times;
    timesWithSchedules;

    constructor(public af: AngularFire) {

        // A list of times, as per your the code in your question:

        this.times = af.database.list(PATH + '/scheduletimes');

        // Compose an observable that adds the schedule for each time. Each
        // emitted value will be an array of time entries. Enumerate the array
        // and add an observable for the time's schedule:

        this.timesWithSchedules = this.times.do(times => times.forEach(time => {

            time.schedule = af.database

                // Query the schedule entries that correspond the time:

                .list(PATH + '/schedule', {
                    query: {
                        orderByChild: 'startTime'
                        startAt: time.time,
                        endAt: time.time
                    }
                })

                // Sort the emmitted array of sessions by title:

                .map(schedule => schedule.sort(compareTitles));

                function compareTitles(a, b) {
                    if (a.title < b.title) {
                        return -1;
                    }
                    if (a.title > b.title) {
                        return 1;
                    }
                    return 0;
                }
        }));
    }
}
<div *ngFor="let time of timesWithSchedules | async">
  <h2>{{time.label}}</h2>
  <div *ngFor="let session of time.schedule | async">
    {{session.title}}
  </div>
</div>
导入'rxjs/add/operator/do';
导入'rxjs/add/operator/map';
导出类ScheduleComponent{
时代;
时间表;
建造商(公共af:AngularFire){
//根据您的问题代码列出的时间列表:
this.times=af.database.list(PATH+'/scheduletimes');
//编写一个可观察的表格,为每一次添加时间表
//发出的值将是一个时间项数组。枚举该数组
//并为时间计划添加一个可观察的:
this.timesWithSchedules=this.times.do(times=>times.forEach(time=>{
time.schedule=af.database
//查询与时间对应的计划条目:
.列表(路径+“/计划”{
查询:{
orderByChild:“开始时间”
时间,时间,
endAt:time.time
}
})
//按标题对emmitted会话数组进行排序:
.map(schedule=>schedule.sort(compareTiles));
函数比较(a、b){
如果(a.标题b.标题){
返回1;
}
返回0;
}
}));
}
}
然后,您的模板将如下所示:

import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';

export class ScheduleComponent {

    times;
    timesWithSchedules;

    constructor(public af: AngularFire) {

        // A list of times, as per your the code in your question:

        this.times = af.database.list(PATH + '/scheduletimes');

        // Compose an observable that adds the schedule for each time. Each
        // emitted value will be an array of time entries. Enumerate the array
        // and add an observable for the time's schedule:

        this.timesWithSchedules = this.times.do(times => times.forEach(time => {

            time.schedule = af.database

                // Query the schedule entries that correspond the time:

                .list(PATH + '/schedule', {
                    query: {
                        orderByChild: 'startTime'
                        startAt: time.time,
                        endAt: time.time
                    }
                })

                // Sort the emmitted array of sessions by title:

                .map(schedule => schedule.sort(compareTitles));

                function compareTitles(a, b) {
                    if (a.title < b.title) {
                        return -1;
                    }
                    if (a.title > b.title) {
                        return 1;
                    }
                    return 0;
                }
        }));
    }
}
<div *ngFor="let time of timesWithSchedules | async">
  <h2>{{time.label}}</h2>
  <div *ngFor="let session of time.schedule | async">
    {{session.title}}
  </div>
</div>

{{time.label}
{{session.title}