NGXS:更新深层嵌套数组状态
因此,我有以下状态:
[
{
name: "Main Tree",
branches: [
{
name: "Branch 1",
branches: []
},
{
name: "Branch 2",
branches: [
{
name: "Sub Branch 1",
branches: []
}
]
}
]
}
]
我的问题是,如何使用状态操作员在分支
中附加另一个分支 sub Branch 1 ?我在此,但它将数据从数组转换为不是所需输出的对象。
同样,上面的情况只是一个示例,我的用例是它可能是内部有分支的无限级分支。
先感谢您。
So I have the following state:
[
{
name: "Main Tree",
branches: [
{
name: "Branch 1",
branches: []
},
{
name: "Branch 2",
branches: [
{
name: "Sub Branch 1",
branches: []
}
]
}
]
}
]
My question is, how do I append another branch under the branches
in Sub Branch 1
using state operators? I tried the solution on this link (State Operators) but it converts the data from array into object which is not the desired output.
Also the above scenario is just an example, my use-case is that it could be an infinite level of sub branches with branches inside them.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该适用于上述示例:
但是,您需要根据上述解决方案为无限树实施递归解决方案。
在此处阅读有关NGXS州运营商的更多信息: https://wwww.ngxs.io/ v/v3.7/高级/操作员
This should work for the above example:
However, you need to implement your recursive solution for the infinite tree based on the above solution.
Read more about NGXS State Operators here: https://www.ngxs.io/v/v3.7/advanced/operators
的嵌套阵列
对于像我成功使用
。我有一个NGXS迭代器的建议,我认为这是严重缺失的。
我稍后再进行更新。
For a nested array like
I used this with success.
I have a proposal for an NGXS iterator which I feel is seriously missing.
I'll update that later.