在我的应用程序中,我有一个仪表板,用户可以在其中添加和删除小部件。为此,我正在使用 angular-gridster2。这很好用,但是当我首先从仪表板添加或删除小部件时,不再显示小部件,然后只有在刷新后才会发生正确的更改。ngFor 指令正在迭代的我的小部件列表是从可观察的构建的。这些值会正确更改。
这是我的html:
<gridster #dashboardgrid [options]="options" class="widget-container">
<gridster-item *ngFor="let widget of widgetList()" (mouseup)="setCurrentWidgetId(widget.id)" [item]="widget.position" class="gridster-design drag-handler">
<!-- some stuff-->
</gridster-item>
在我ngOnInit
的订阅中,我订阅了可观察的:
this.dataService.currentDashboardId.subscribe(dashboardId => this.currentDashboardId = dashboardId);
this.dataService.currentSheetId.subscribe(sheetId => this.currentSheetId = sheetId);
this.dataService.projectData
.subscribe((project: Project) => {
this.project = project;
});
这是返回list of widgets
应该显示的方法:
widgetList(): Array<Widget> {
return this.project.dashboards
.find(x => x.id === this.currentDashboardId).sheets
.find(x => x.id === this.currentSheetId).widgets;
}
我真的找不到这种行为的原因,所以如果有人这样做,我很感激。提前致谢。