首页 > 解决方案 > kendo-scheduler 的 base-edit.service 中的 source 做了什么?

问题描述

我正在尝试了解 kendo-ui 中的编辑服务示例(链接),以了解调度程序的角度(处于测试阶段)。EditService 类扩展了 BaseEditService。

我的代码中 editService 的 read() 函数如下所示:

public read(): void {
    if (this.data.length) {
        this.source.next(this.data);
        return;
    }

    this.fetch().subscribe(data => {
        this.data = data.map(item => this.readEvent(item));
        this.source.next(this.data);
    },null, null
    );
}

我不明白this.source.next(this.data)做了什么。

根据base-edit.service.d.ts:

/**
* The source subject for the `events` observable.
*/
protected source: BehaviorSubject<TEvent[]>;

深入研究 BehaviorSubject(来自 RxJS)会显示一条评论

* A variant of Subject that requires an initial value and emits its current
* value whenever it is subscribed to.

我开始认为 this.data 需要输入到 this.source.next() 中,原因是它没有在一行中完成,如下所示

 this.source.next(data.map(item => this.readEvent(item)));

是因为当数据已经存在时,它需要 if 语句。

标签: angularkendo-uirxjskendo-scheduler

解决方案


推荐阅读