如何从ngrx-entity商店中选择一个唯一的实体

发布于 2025-02-03 18:27:53 字数 1218 浏览 4 评论 0 原文

我在我的ngrx-entity商店中prsnls实体很好地描述为对象数组。 img src =“ https://i.sstatic.net/8skp2.png” alt =“在此处输入图像说明”>

我能够选择这样的所有PRSNL实体:

export const selectAllPrsnls = createSelector(
    selectPrsnlState,
    prsnlsState => {
        const allPrsnls = Object.values(prsnlsState.entities)
        return allPrsnls;
    }
);

但是我无法获得它的ID唯一PRSNL。这就是我所做的:

export const selectUniquePrsnls = (id:string) => createSelector(
    selectPrsnlState,
    prsnlsState => {
        const uniquePrsnls = Object.values(prsnlsState.entities[id])
        return uniquePrsnls;
    }
  );

唯一的prsnl不会被拿走,因为当我安装时。这就是我订阅它的方式:

getUniquePersnlValues(id:string){
    this.store
    .pipe(select(selectUniquePrsnls), map((per) => per))
    .subscribe((value: any) => this.uniquePrsnl = value);
    console.log('prsnl', this.uniquePrsnl);
  }

我认为我无法对此问题进行故障排除,因为我不太了解 selectprsnlstate 在创建srrenshot上的选择时是什么:

在这种情况下,我如何从PRSNL实体中获得唯一的PRSNL。任何帮助都非常感谢。提前致谢。

I have in my ngrx-entity store the prsnls entity well described as array of objects as shown in redux devtool.enter image description here

I'm able to select all prsnl entities like this:

export const selectAllPrsnls = createSelector(
    selectPrsnlState,
    prsnlsState => {
        const allPrsnls = Object.values(prsnlsState.entities)
        return allPrsnls;
    }
);

But I'm unable to get a unique prsnl by it's id. This is what I did:

export const selectUniquePrsnls = (id:string) => createSelector(
    selectPrsnlState,
    prsnlsState => {
        const uniquePrsnls = Object.values(prsnlsState.entities[id])
        return uniquePrsnls;
    }
  );

The unique prsnl is not fetched because when I console.log after susbscribing to the createSelector observable, I get undefined in the console. This is how I subscribed to it:

getUniquePersnlValues(id:string){
    this.store
    .pipe(select(selectUniquePrsnls), map((per) => per))
    .subscribe((value: any) => this.uniquePrsnl = value);
    console.log('prsnl', this.uniquePrsnl);
  }

I think I'm not able to troubleshoot this issue because I don't understand well what does the selectPrsnlState when creating the selector like on srrenshot:
enter image description here

How can I then get a unique prsnl from the prsnls entities in this situation. Any help is much appreciated. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痕至 2025-02-10 18:27:53

您可以通过ID获得元素:

export const selectUniquePrsnls = (id:string) => createSelector(
    selectPrsnlState,
    prsnlsState => prsnlsState.entities[id]
  );

You can get element by id like this:

export const selectUniquePrsnls = (id:string) => createSelector(
    selectPrsnlState,
    prsnlsState => prsnlsState.entities[id]
  );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文