recursion - Angular2递归组件输出

标签 recursion angular tree

我有以下问题: 假设我有 Component A,它有两个 subcomponents ArAdSubcomponent Ar 是递归创建的树,subcomponent Ad 是显示递归树中所选节点详细信息的组件(subcomponent Ar)。如何使用 @Output 将选定的节点从 Ar 中的子(子)组件发送到 Component Ad?应该是 @Output 还是其他什么?

app.component.html:

<tree [input]="fooTree" [output]="updateDetails($event)"></tree>
<tree-details [input]="input"></tree-details>

tree.component.html:

<tree [input]="fooTree.children"></tree>

tree-details.component.html

<div>{{input.name}}</div>
<div>{{input.id}}</div>

在这种情况下,我只会看到根树的详细信息,我如何才能从其他节点(递归创建的节点之一)获取信息,何时选择?

最佳答案

更新:

在演示应用程序中更容易看到:https://plnkr.co/edit/WaYluZyPaC0OEV0YovbC?p=preview

..

您的树组件 Ar 可以有一个@Ouput()。 您的 AppComponent 将使用此输出并将所选数据发布到第二个子组件 detail-component

app.component.html

<tree (yourOutputNameHere)="yourFunctionToReceiveAndPostSelectedData($event)"></tree>
<details #yourDetailViewComponent></details>

tree.component.html

<tree (yourOutputNameHere)="yourFunctionToReceiveAndPostSelectedData($event)"></tree>

你的 tree-component 甚至可以有一个 @Input() 并且在你的模板中你可以做这样的事情:

app.component.html

<tree [detail-view-input]="yourDetailViewComponent"></tree>
<details #yourDetailViewComponent></details>

tree.component.html

<tree [detail-view-input]="detailViewInput"></tree>

关于recursion - Angular2递归组件输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39611536/

相关文章:

java - 如何回滚返回特定值的递归函数

java - 如何将元素列表添加到二叉搜索 TreeMap 中?

recursion - 连续两次相同的 echo 调用在 Vim 函数中具有不同的输出

Java 中的 java.util.Random 和递归

python - 使用递归查看随机列表时如何跟踪偶数的数量

javascript - 观察者订阅不会在第一次加载到组件时触发

javascript - 侧边栏高度随内容长度变化

javascript - Angular 2+ Observables 和 Javascript 语法

algorithm - 2-3棵树,数据存储

java - Java的TreeSet和TreeMap用的是什么树?