1

在将数据字段添加到商店之前,我需要对其进行解析。

我希望从覆盖 getAll() 中解析数据字段。
此代码不起作用有人可以解释为什么吗?

export interface Alert {
  id: string;
  data: any;
}

const entityMetadata: EntityMetadataMap = {
  Alert: {}
};


@Injectable({providedIn: 'root'})
export class AlertService extends EntityCollectionServiceBase<Alert> {
  constructor(serviceElementsFactory: EntityCollectionServiceElementsFactory) {
    super('Alert', serviceElementsFactory);
  }

  getAll(options?: EntityActionOptions): Observable<Alert[]> {
    return super.getAll(options)
      .pipe(
        map(alerts => {
          alerts = alerts.map((alert: any) => ({...alert, data: JSON.parse(alert.data)}));
          return alerts;
        })
      );
  }

4

0 回答 0