从对象数组中获取一些字符串值并将这些值添加到可观察对象中

Get some string values from an object Array and add those values into an observable

这是对象数组

workflows: ProteusWorkflow[]

ProteusWorkflow obj 看起来像这样

export class ProteusWorkflow{
    id: number;
    workflowName :string
}

我需要将数组上方的所有工作流名称添加到

filteredWorkflowsNew$: Observable<string[]>;

我该怎么做?请帮帮我!!

我已经试过了...

this.workflows.forEach(w => {
      this.filteredWorkflowsNew$.pipe(map(wfs=>{
        wfs.push(w.workflowName);
        return this.filteredWorkflowsNew$;
      }));
    });

但没用。

您可以使用 Array.prototype.map() 运算符。

map() function creates a new array populated with the results of calling a provided function on every element in the calling array. Please find more details about use of Array.prototype.map() here.

let workflows = [{id:1,workflowName:"ABC"},{id:1,workflowName:"BDF"},{id:1,workflowName:"EWQ"}];
let filteredWorkflowsNew$=[];

filteredWorkflowsNew$ = workflows.map(obj => obj.workflowName);

console.log(filteredWorkflowsNew$) // ["ABC","BDF","EWQ"]