Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.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
Angular Firebase查询今日获取';s的预订传递回数组_Angular_Typescript_Firebase_Firebase Realtime Database_Angularfire2 - Fatal编程技术网

Angular Firebase查询今日获取';s的预订传递回数组

Angular Firebase查询今日获取';s的预订传递回数组,angular,typescript,firebase,firebase-realtime-database,angularfire2,Angular,Typescript,Firebase,Firebase Realtime Database,Angularfire2,我正在尝试从firebase返回所有今天匹配的预订 todayBookings() { this.ordersData = this.af.list('/orders', { query: { orderByChild: 'start', // equalTo: today } }); this.ordersData.subscribe((res) => { this

我正在尝试从firebase返回所有今天匹配的预订

todayBookings() {

    this.ordersData = this.af.list('/orders', {

        query: {
            orderByChild: 'start',
            // equalTo: today
        }
    });
    this.ordersData.subscribe((res) => {
        this.orders = res;
    });

    this.orders.forEach(order => {

        var d = new Date();
        var curr_date = ("0" + (d.getDate() + 0)).slice(-2);
        var curr_month = ("0" + (d.getMonth() + 1)).slice(-2)
        var curr_year = d.getFullYear();
        // get today's date
        var today = curr_year + "-" + curr_month + "-" + curr_date;
        // get date of booking
        var dateOfBooking = order.start.substr(0, 10);

        if (dateOfBooking == today) {
            this.todaysOrders = order;
            var index = this.orders.indexOf(order, 0);
            if (index > -1) {
                this.orders.splice(index, 1);
            }
            // console.log(this.orders);
            // console.log(this.todaysOrders);

        }

    });

    this.orders = this.todaysOrders
    console.log(this.orders);
}
我在html中使用*ngFor order of orders打印所有返回的订单

在firebase数据库中,我保存了7个预订。7个中有2个是今天的日期。所以所有7个都在屏幕上打印出来了。但是,当我单击我的按钮运行以下功能时,我只想显示今天日期的预订

todayBookings() {

    this.ordersData = this.af.list('/orders', {

        query: {
            orderByChild: 'start',
            // equalTo: today
        }
    });
    this.ordersData.subscribe((res) => {
        this.orders = res;
    });

    this.orders.forEach(order => {

        var d = new Date();
        var curr_date = ("0" + (d.getDate() + 0)).slice(-2);
        var curr_month = ("0" + (d.getMonth() + 1)).slice(-2)
        var curr_year = d.getFullYear();
        // get today's date
        var today = curr_year + "-" + curr_month + "-" + curr_date;
        // get date of booking
        var dateOfBooking = order.start.substr(0, 10);

        if (dateOfBooking == today) {
            this.todaysOrders = order;
            var index = this.orders.indexOf(order, 0);
            if (index > -1) {
                this.orders.splice(index, 1);
            }
            // console.log(this.orders);
            // console.log(this.todaysOrders);

        }

    });

    this.orders = this.todaysOrders
    console.log(this.orders);
}
当我控制台记录以下内容时:console.log(this.todaysOrders)

我在控制台中看到今天的两个预订:

不幸的是,我不知道现在如何处理这个.Today排序器并将它们传递回这个.orders

我尝试了以下方法:

this.orders.push(this.todaysOrders)

但它带回了所有条目,并将今天的预订添加到列表中,因此,它返回的条目不是7条,而是9条。(所有预订+今天日期的两次预订)

数据库中的订单

orders
 -Ko2a0zwYPQc-ocfJ1cF
   createdAt: 1499003887000
   orderId: 34681
   partySize: "1"
   requirements: "none"
   start: "2017-07-02T15:00:44+01:00"
   status: "Accepted"
   type: "tablebooking"
   + userDetails
   userId: "CQbDG6H8ENStlZiaNOGNsvbw2GL2"

   -Ko2ay19E7b17UhZ9HAf
   -Ko2pmavUZNTKdsr0pv6
   -Ko2t6cm35uOtiROeghG
   -Ko2tn6iRmkG7Y-OfAcJ
   -Ko2u5FrD5ZnIphL9Vno
   -KoBtilv2-dj-XmQSQBf
这是全班同学。我已经剥离了其他功能,我正在为页面上的其他内容使用

import { Component, OnInit, AfterViewInit, ElementRef, ViewChild, OnDestroy, OnChanges } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database';
import { Router, ActivatedRoute } from "@angular/router";
import { NgForm } from '@angular/forms';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase';
import { ToastrService } from 'toastr-ng2';
import * as moment from 'moment';


@Component({
    selector: 'app-calendar',
    templateUrl: './calendar.component.html',
    styleUrls: ['./calendar.component.scss']
})

export class CalendarComponent implements OnInit, AfterViewInit, OnChanges {



    order: Array<any>;
    orders: Array<any>;
    ordersData: FirebaseListObservable<any>;

    todaysOrders: Array<any>;

    color: any;
    orderId: any;


    @ViewChild('fullcalendar') fullcalendar: ElementRef;


    constructor(public af: AngularFireDatabase, public toastr: ToastrService, public router: Router, public authentication: AngularFireAuth) {


        this.ordersData = af.list('/orders', {
            query: {
                orderByChild: 'start',
            }
        });
        this.ordersData.subscribe((res) => {
            this.orders = res;
        });


    }




    //Get Todays Bookings
    todayBookings() {

        this.ordersData = this.af.list('/orders', {

            query: {
                orderByChild: 'start',
                // equalTo: today
            }
        });
        this.ordersData.subscribe((res) => {
            this.orders = res;
        });

        this.orders.forEach(order => {

            var d = new Date();
            var curr_date = ("0" + (d.getDate() + 0)).slice(-2);
            var curr_month = ("0" + (d.getMonth() + 1)).slice(-2)
            var curr_year = d.getFullYear();
            // get today's date
            var today = curr_year + "-" + curr_month + "-" + curr_date;
            // get date of booking
            var dateOfBooking = order.start.substr(0, 10);

            if (dateOfBooking == today) {
                this.todaysOrders = order;
                var index = this.orders.indexOf(order, 0);
                if (index > -1) {
                    this.orders.splice(index, 1);
                }
                // console.log(this.orders);
                console.log(this.todaysOrders);

            }

        });

        // this.orders = this.todaysOrders
        // console.log(this.orders);
    }





}
import{Component,OnInit,AfterViewInit,ElementRef,ViewChild,OnDestroy,OnChanges}来自“@angular/core”;
从“angularfire2/database”导入{AngularFireDatabase,FirebaseListObservable,FirebaseObjectObservable};
从“@angular/Router”导入{Router,ActivatedRoute}”;
从'@angular/forms'导入{NgForm};
从'angularfire2/auth'导入{AngularFireAuth};
从“firebase”导入*作为firebase;
从“toastr-ng2”导入{ToastrService};
从“时刻”导入*作为时刻;
@组成部分({
选择器:“应用程序日历”,
templateUrl:“./calendar.component.html”,
样式URL:['./calendar.component.scss']
})
导出类CalendarComponent实现OnInit、AfterViewInit、OnChanges{
顺序:数组;
顺序:数组;
ordersData:FirebaseListObservable;
今日排序器:数组;
颜色:任意;
orderId:任意;
@ViewChild(“fullcalendar”)fullcalendar:ElementRef;
构造函数(公共af:AngularFire数据库、公共toastr:ToastrService、公共路由器:路由器、公共身份验证:AngularFireAuth){
this.ordersData=af.list(“/orders”{
查询:{
orderByChild:“开始”,
}
});
this.ordersData.subscribe((res)=>{
这个命令=res;
});
}
//获得今天的预订
今日订票{
this.ordersData=this.af.list(“/orders”{
查询:{
orderByChild:“开始”,
//今天
}
});
this.ordersData.subscribe((res)=>{
这个命令=res;
});
this.orders.forEach(order=>{
var d=新日期();
var curr_date=(“0”+(d.getDate()+0)).slice(-2);
var curr_month=(“0”+(d.getMonth()+1)).slice(-2)
var curr_year=d.getFullYear();
//得到今天的日期
今日风险值=当前年份+“-”+当前月份+“-”+当前日期;
//获取预订日期
var dateOfBooking=order.start.substr(0,10);
如果(预订日期==今天){
this.todaysOrders=订单;
var index=this.orders.indexOf(order,0);
如果(索引>-1){
本.订单.拼接(索引,1);
}
//console.log(this.orders);
console.log(this.todaysOrders);
}
});
//this.orders=this.todaysOrders
//console.log(this.orders);
}
}

您可以从
订单
数组中删除今天的每个订单

比如:

if (dateOfBooking == today) {
  this.todaysOrders = order;
  var index = this.orders.indexOf(order, 0);
  if (index > -1) {
    this.orders.splice(index, 1);
  }
  console.log(this.todaysOrders);
  console.log(this.orders);
}

我的数据库是firebase不知道你的意思buddyShow我们在你的数据库中是什么,布局/结构更新的主要帖子:)谢谢你的建议@Lilrom然而,在控制台中我看到这删除了今天的订单,我不想删除它们,这是我需要显示的订单,我想删除所有不是今天日期的订单。可能类似于
this.orders=this.todaysOrders
,在您的
forEach
之后?恐怕也不行。当我使用console.log(this.orders)时,我得到了一个不是今天预订的对象数组。当我使用console.log(this.todaysOrders)时,我会返回今天的订单,但作为单个对象,而不是我需要的对象数组。我还在foreach之后添加了this.orders=this.todaysOrders,但在控制台中出现错误:error:error尝试区分“[object]”。只允许数组和iterables。我已经用你的附加代码更新了我的问题。我发现了这个有用的文档。你读过吗?你们能分享你们所有的课程吗?在主帖子中增加了完整的课程。谢谢你的链接也,它有很好的信息,我一定会利用。