0

我尝试了各种排列。我要做的是执行 get 以通过 Id 检索对象,然后修改该对象的属性,然后将其发布回来,这样我就可以有效地更新对象。

这是我尝试过的:

  archive(orgId: number, id: number): Observable<Aircraft> {
    return this.http.get<Aircraft>('/api/organisations/' + orgId + '/aircrafts/' + id)
        .pipe(mergeMap( a => {
          console.log(a);
        return this.http.post<IAircraft>('/api/organisations/' + orgId + '/aircrafts/' + a.id, a).subscribe();
      });
  }

结果:错误类型错误:您在预期流的位置提供了无效对象。您可以提供 Observable、Promise、Array 或 Iterable。

archive(orgId: number, id: number): Observable<Aircraft> {
    return this.http.get<Aircraft>('/api/organisations/' + orgId + '/aircrafts/' + id)
      .map((data) => {
      return data.current = false;
    })
        .pipe(mergeMap( a => {
        return this.http.post<IAircraft>('/api/organisations/' + orgId + '/aircrafts/' + a.id, a).subscribe();
      }));
  }

错误类型错误:无法在布尔值“false”上创建属性“id”和

restore(orgId: number, id: number): Observable<Aircraft> {
    return this.http.get<Aircraft>('/api/organisations/' + orgId + '/aircrafts/' + id)
      .pipe(
        mergeMap( a => {
          a.current = true;
          return this.http.post<IAircraft>('/api/organisations/' + orgId + '/aircrafts/' + a.id, a).subscribe();
        }));
  }

错误类型错误:您在预期流的位置提供了无效对象。您可以提供 Observable、Promise、Array 或 Iterable。

完整的错误:

core.js:1448 ERROR TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
    at subscribeToResult (subscribeToResult.js:74)
    at MergeMapSubscriber._innerSub (mergeMap.js:138)
    at MergeMapSubscriber._tryNext (mergeMap.js:135)
    at MergeMapSubscriber._next (mergeMap.js:118)
    at MergeMapSubscriber.Subscriber.next (Subscriber.js:92)
    at MapSubscriber._next (map.js:85)
    at MapSubscriber.Subscriber.next (Subscriber.js:92)
    at FilterSubscriber._next (filter.js:90)
    at FilterSubscriber.Subscriber.next (Subscriber.js:92)
    at MergeMapSubscriber.notifyNext (mergeMap.js:151)

我只是似乎无法正确地绘制地图,如果我将地图拿出来,它可以工作,但是没有意义。我也尝试将各种地图结果转换为可观察对象,但似乎 API 看穿了我的诡计,并继续抛出相同的错误。

谁能告诉我这应该如何工作?

编辑我一直在玩它 - 这是最新的化身:

  archive(orgId: number, id: number): Observable<any> {
    return this.http.get<Aircraft>('/api/organisations/' + orgId + '/aircrafts/' + id)
      .pipe(
        mergeMap(a => {
          console.log(a.constructor.name);
          console.log(a);
           a.current = false;
         return this.http.post<IAircraft>('/api/organisations/' + orgId + '/aircrafts/' a.id, a);
        }));   }

console.log(a.constructor.name) 返回“object”——非常有用

console.log(a) 返回

这个控制台输出

4

0 回答 0