gpt4 book ai didi

javascript - 将数组中的管道与 Angular Observable 组合起来

转载 作者:行者123 更新时间:2023-12-02 23:52:09 24 4
gpt4 key购买 nike

我有 Observable,我将其通过管道传输到多个管道,如下所示。

getOrders(filters: any, page: any = 1, orderBy: string = 'deliver_on', sort: string = 'asc') {

const opCityPipe = pipe(
filter((obj: any) => obj.payload.order.op_city_id === 1)
);

const storeRefPipe = pipe(
filter((obj: any) => obj.payload.order.store.ref.match(/^Your.*/))
);

const statusPipe = pipe(
filter((obj: any) => ['assign_request', 'accepted',
'in_store', 'en_route_to_client', 'arrived',
'canceled'].indexOf(obj.payload.order.status) !== -1)
);

return Observable.create((observer: Observer<any>) => {
this.socket.on('private-order.status.changed.1:order.status',
(obj: any) => {
observer.next(obj);
});
}).pipe(opCityPipe, storeRefPipe, statusPipe);
}

如何将管道设置为数组?我想动态填充它。我尝试添加数组但出现错误。

ERROR TypeError: Object(...)(...) is not a function

我想做类似的事情

const pipes = [opCityPipe, storeRefPipe, statusPipe];
Observable.pipe(pipes);

更新解决方案

Observable.pipe(...pipes);

最佳答案

我认为这应该可行,但您收到的错误尚不清楚。

getOrders(filters: any, page: any = 1, orderBy: string = 'deliver_on', sort: string = 'asc') {

const opCityPipe = filter((obj: any) => obj.payload.order.op_city_id === 1);

const storeRefPipe = filter((obj: any) => obj.payload.order.store.ref.match(/^Your.*/));

const statusPipe = filter((obj: any) => ['assign_request', 'accepted',
'in_store', 'en_route_to_client', 'arrived',
'canceled'].indexOf(obj.payload.order.status) !== -1);

const filters = [opCityPipe, storeRefPipe, statusPipe]

return Observable.create((observer: Observer<any>) => {
this.socket.on('private-order.status.changed.1:order.status',
(obj: any) => {
observer.next(obj);
});
}).pipe(...filters);
}

关于javascript - 将数组中的管道与 Angular Observable 组合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55595368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com