我需要构建对象,并将其提供给完整的日历事件输入。但我无法生成动态对象。
这是我的目标:
import { EventInput } from '@fullcalendar/core';
...
events: EventInput[];
this.events = [ { title: '', allDay: false, start: choosenStartDate, end :choosenEndDate, backgroundColor: RateColor.SpecialRate, borderColor: RateColor.SpecialRate },];
如果我有多个对象,那么我想加入那个数组,但我做不到
let obj1:EventInput = { title: '', allDay: false, start: specialRateStartDate, end :specialRateEndDate, backgroundColor: RateColor.SpecialRate, borderColor: RateColor.SpecialRate };
let obj2 :EventInput= { title: '', allDay: false, start: normalRateFirstStartDate, end :normalRateFirstEndDate, backgroundColor: RateColor.NormalRate, borderColor: RateColor.NormalRate };
let obj3:EventInput = { title: '', allDay: false, start: normalRateSecondStartDate, end :normalRateSecondEndDate, backgroundColor: RateColor.NormalRate, borderColor: RateColor.NormalRate }
当我尝试this.events.push(obj1);
时,我得到错误为ERROR TypeError: Cannot read property 'push' of undefined
如果this.events=[obj1,obj2,obj3,obj4,obj5...];
有效,但我想从循环插入
您应该添加=[]到数组声明:
events: EventInput[] = [];
数组未初始化!!