FullCalendar有一个名为Scheduler的附加组件,我试图与PrimeNG-Schedule组件一起使用.查看PrimeNG文档,我可以使用“选项”属性向FullCalendar发送任意信息.这确实有效,但是当我将数据检索连接到异步API时,会导致问题.
API使用Observables然后我在组件中订阅.这适用于事件,因为视图在事件更改时自动更新.
但是,当通过PrimeNG’选项’属性向FullCalendar提供’资源’时,事情不能按预期工作,因为设置’options’属性的代码在API调用有机会返回之前运行,因此空.
我确信这一点,因为如果我对资源进行硬编码,就会有所作为.
>使调用同步(希望避免这种情况)
>等待加载所有数据,然后(重新)渲染视图(使其与#1几乎相同)
>配置options.resources属性,以便在更改时,视图会更新,就像它对事件一样(这是最好的选择,但不确定它是否可能)
我将不胜感激任何帮助.谢谢.
<p-schedule [events]="events" [businessHours]="businessHours" [options]="optionConfig" > </p-schedule>
我的(现在)虚拟API
getEvents() { return this.http .get('assets/api/mockEvents.json') .map((response : Response) => <Appointment[]>response.json().data) .catch(this.handleError); } getResources() { return this.http .get('assets/api/mockResources.json') .map((response : Response) => <Resource[]>response.json().data) .catch(this.handleError); }
组件文件
ngOnInit() { this.schedulerService.getEvents() .subscribe(events=> this.events = events); this.schedulerService.getResources() .subscribe(resources => this.resources = resources); // ***** If the following code is uncommented,resources are displayed in Schedule view **** // this.resources = [ // new Resource(1,"Dr. Hibbert","blue",true,new BusinessHours("08:00","16:00")),// new Resource(2,"Dr. Simpson","green",new BusinessHours("10:00","18:00")) // ]; this.optionConfig = { "resources": this.resources } }
编辑:我想到的一件事是,只能通过它的setter方法设置this.resources属性.这样,我确切地知道何时设置了值,但问题仍然存在,如何在初始化之后将新值推送到调度组件.