0

我从这个函数中获取项目的 id,我想将这些 id 作为数组发送并使用 getAll() 检索它

    const queryParams: Record<string, string[]> = selectedItems.reduce(
      (acc, curr, index) => ({
        ...acc,
        ['item'] : curr.id
      }),
      {}
    );

    this.router.navigate(['/goToItems'], {
      queryParams
    });

我尝试了类似的方法,但没有得到数组。我想创建这样的东西:

  this.router.navigate(['/goToItems'], {
      item: [1, 2, 3, 4, 5] // this array should be queryParams
    });

请你能与我分享如何实现这一点的任何想法吗?

4

1 回答 1

0

它需要作为queryParams财产发送。尝试以下

this.router.navigate(['/goToItems'], {
  queryParams: { item: [1, 2, 3, 4, 5] }
});

并像这样在收件人中获取它

this.route.snapshot.queryParamMap.get('item');
于 2021-10-22T08:03:27.730 回答