gpt4 book ai didi

reactjs - redux 重新选择关系数据的选择器

转载 作者:行者123 更新时间:2023-12-02 04:38:48 25 4
gpt4 key购买 nike

选择器有 2 个参数,state 和 props,但是我们如何处理关系数据的选择器?

initialState = {
department :{ids:[1],byId:{name:'dep 1',id:1,parent:null}}
sections :{ids:[2],byId:{name:'section 1.1',id:2,parent:1}}
subsections :{ids:[3],byId:{name:'subsection 1.1.1',id:3,parent:2}}
}

这里的部门是 n(sections) 的父级和 n(subsections) 的祖父级

<Department id="1" />我想选择部门 1 及其所有子级。

如何在不将我需要的部门 ID 传递给选择器的情况下编写这样的选择器?

最佳答案

您可以使用路由器(react-router)通过 url 段传递此类 key ,然后您可以访问所需的 ID,即:

mapStateToProps(state, ownProps) {
// then get access to id here
console.log(ownProps.params.department_id);
}

关于reactjs - redux 重新选择关系数据的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39214573/

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