我有以下代码:
//Loop: For each user ID/Role ID, get the data
userMeta.forEach((businessRole) => {
  Observable.forkJoin(
    af.database.object('/roles/'+businessRole.$value),
    af.database.object('/users/'+businessRole.$key)
  ).subscribe(
    data => {
      console.log("Data received");
      data[1].role = data[0];
      this.users.push(data[1]);
    },
    err => console.error(err)
  );
我试图订阅使用2个observable的结果forkJoin.
由于某些原因,未显示"已接收数据"消息.
我的userMeta变量在console.log中看起来很好:
怎么了?
更新:以下代码也不返回任何内容
let source = Observable.forkJoin(
        af.database.object('/roles/'+businessRole.$value),
        af.database.object('/users/'+businessRole.$key)
    );
    let subscription = source.subscribe(
      function (x) {
    console.log("GOT: " + x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });
我实际上要做的是提高以下代码的性能:
//Subscription 3: role ID to role Name
        af.database.object('/roles/'+businessRole.$value) …我的软件中有几个案例,其中我有一组可观察对象,我需要按顺序执行它们。只有在前一个订阅完成后才会进行下一个订阅。
所以我使用concat运营商。它工作得很好,但是每次完成其中一个时都会触发它的订阅Observables,并且我需要在一切完成后才触发它。
concat(
  of(1, 2, 3).pipe(delay(3000)),
  // after 3s, the first observable will complete and subsquent observable subscribed with values emitted
  of(4, 5, 6).pipe(delay(3000)),
)
  // log: 1,2,3,4,5,6
  .subscribe((v) => {
  // Needs to be triggered once after everything is complete
    console.log(v);
  });
我需要一种方法来管理这个 observable,这样订阅只会在一切完成后触发一次,在这种情况下订阅的值并不重要,因此可以省略它。
如果可能,可以在订阅上下文中以数组的形式提供这些值。