rxjs .pipe()添加一些项目到结果数组
我需要在从阿波罗获得的结果数组中添加一些静态值。这是我的代码过滤数组并按名称按字母顺序排列,这就是为什么我想在这2个管道之间添加项目:
return this.myService
.loadCards()
.pipe(
map((allCards) =>
allCards.filter((card) =>
card.name.toLowerCase().includes(searchQuery.toLowerCase()),
),
),
)
.pipe( // Insert 3 hardcoded objects here)
.pipe(
map((allCards) =>
allCards.sort((a, b) => {
if (a.name.toLowerCase() < b.name.toLowerCase()) return -1;
if (a.name.toLowerCase() > b.name.toLowerCase()) return 1;
return 0;
}),
),
);
I have a need of adding some static values to the result array that i get from apollo. Here is my code that filters the array and sorts it alphabetically by name, that is why i want to add items in between those 2 pipes:
return this.myService
.loadCards()
.pipe(
map((allCards) =>
allCards.filter((card) =>
card.name.toLowerCase().includes(searchQuery.toLowerCase()),
),
),
)
.pipe( // Insert 3 hardcoded objects here)
.pipe(
map((allCards) =>
allCards.sort((a, b) => {
if (a.name.toLowerCase() < b.name.toLowerCase()) return -1;
if (a.name.toLowerCase() > b.name.toLowerCase()) return 1;
return 0;
}),
),
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以加入两个阵列,例如[... arrayone,... arraytwo],因此请尝试(您可以在额外的地图中移动它,但不必这样做):
you can concatenate two arrays like [...arrayone,...arraytwo], so try this (you can move it in an extra map but you don't have to):