Typescript 可观测的

Typescript 可观测的,typescript,rxjs,rxjs6,Typescript,Rxjs,Rxjs6,我有一个返回对象数组的方法 我需要按照某个标准对其进行过滤,然后创建一个新的对象数组,其中的数据将转换为另一个模型 然后返回结果数组,然后订阅它 public getTestWithPare(): Observable<Array<TestModel>> { return this.http.getTests().pipe( flatMap(rate => rate), // splitting array filter(t

我有一个返回对象数组的方法

我需要按照某个标准对其进行过滤,然后创建一个新的对象数组,其中的数据将转换为另一个模型

然后返回结果数组,然后订阅它

public getTestWithPare(): Observable<Array<TestModel>> {

    return this.http.getTests().pipe(
        flatMap(rate => rate), // splitting array
        filter(test => !test.isDone),
        map(test => {

            const testPare = new TestModel();
            testPare.key = `${test.id}/${test.name}`;
            if (test.type === 'new') {
                testPare.finish = test.value;
                testPare.show = true;
            } else {
                testPare.start = test.value;
                testPare.hide = true;
            }

            return testPare;
        }),
        concatAll(),
        toArray()
    );
}
调用该方法后,我得到一个错误:

您提供了一个无效的对象,其中需要流。你可以 提供一个可观察的、承诺的、阵列的或可观察的

我不明白怎么了

我想在输出端得到一个对象数组


大致采用这种格式:['key':{key:'1/t',finish:7,show:true},…]

Rxjs在这里是过度杀伤力的,只有当您有大数组并且您不想用一次性的用户数组方法来处理它时

const testToTestPare = test => {
  /* If you don't need TestMode, create an empty object const testPare = {} */
  const testPare = new TestModel(); 
  testPare.key = `${test.id}/${test.name}`;
  if (test.type === 'new') {
    testPare.finish = test.value;
    testPare.show = true;
  } else {
    testPare.start = test.value;
    testPare.hide = true;
  }
  return testPare;
};


public getTestWithPare(): Observable<Array<TestModel>> {
    return this.http.getTests().pipe(
        map(tests => tests.map(testToTestPare)),
    );
}

你可以参考这里类似问题的答案-我看了,但这不是我的真实情况我想将可观察到的整合到一个数组中也许我做得不对简单地移除concatAll怎么样?toArray应该足够了,如果我正确理解您的案例,它将返回一个模型数组[TestModel,TestModel,…],并且进一步使用它们不是很方便。因为我想返回格式为['key':{key:'1/t',finish:7,show:true},…]的数组。这样我就可以通过键值从这个对象获取html