我试图创建类似于角度示例的可扩展行。 Example
当前,我的数据源是一个BehaviorSubject,它在connect方法中返回一个Observable。
如何在现有代码中附加其他行?
private gizmoSubject = new BehaviorSubject<Gizmo[]>([]);
connect(collectionViewer: CollectionViewer): Observable<Gizmo[]> {
const rows = [];
this.gizmoSubject.forEach(x => rows.push(x, { detailRow: true, x }));
console.log(rows);
return of(rows);
// This was the original code.
//return this.gizmoSubject.asObservable();
}
当我从API获取数据时,我首先尝试处理此问题,但我也无法使其正常工作。
loadGizmos(findParams: GizmoParameters) {
this.loadingSubject.next(true);
this.gizmoService.findGizmos(findParams)
.pipe(
finalize(() => this.loadingSubject.next(false))
)
.subscribe(x => {
this.gizmoSubject.next(x);
});
}
答案 0 :(得分:0)
private rows = []
private gizmoSubject = new BehaviorSubject<Gizmo[]>([]);
connect(collectionViewer: CollectionViewer): Observable<Gizmo[]> {
return this.gizmoSubject.asObservable().pipe(
map(x => {
this.rows.push(x, { detailRow: true, x })
return rows
}
)
}