gpt4 book ai didi

angular - NGRX 和嵌套关系示例

转载 作者:太空狗 更新时间:2023-10-29 17:58:17 24 4
gpt4 key购买 nike

有没有人有将 NGRX 与超过 1 级深度的相关/嵌套数据一起使用的示例?似乎只有使用 ngrx 的简单示例,而我还没有看到真实世界的示例?

我目前已将 ngrx 从我的项目中移除,因为在缺乏文档或超过 1 个表的示例的情况下尝试在高级级别上尝试找出需要很长时间,我尝试使用实体但速度变慢了开发,仍然不知道如何使用相关实体。 1 个级别没问题,但多个级别似乎这可能会使事情复杂化。

我想看一个包含多个表和关系的示例。似乎我已经用分派(dispatch)多个 Action 替换了 forkJoin?有没有一种方法可以将多个 Action 作为一个 Action 来分派(dispatch),例如加载任务、加载用户、加载契约(Contract)?

我的结构看起来是这样的:

Task
-TaskId
-Title
-AssignedToUser (User)
-Attachments (Array of Attachments)
-Comments (Array of Comments)
-Reviewers (Array of Users)
-Approvers (Array of Users)

Comment
-CommentId
-CommentText
-User (User)


User
-UserId
-Name
-Contracts (Array of Contracts)
-Roles (array of Roles)


Contract
-ContractId
-ContractName

Role
-RoleId
-RoleName

来自网络 api 的数据是嵌套的 json,所以我不确定如何转换,为所有这些创建选择器,所以如果有人有类似的样本,那将非常有帮助。我了解 NGRX 的大部分内容,但对如何为所有这些构建选择器感到困惑。

最佳答案

经过一些研究和更多的挖掘,我想我正在寻找像 Normalizr 这样的库:https://github.com/paularmstrong/normalizr并在 Redux 上找到了一篇解释更多关于嵌套数据的帖子:

https://redux.js.org/recipes/structuringreducers/normalizingstateshape

关于angular - NGRX 和嵌套关系示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52839081/

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