Angular2 递归树展开所有 [英] Angular2 recursive tree expand all

查看:61
本文介绍了Angular2 递归树展开所有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有递归树组件,我想在从父组件单击时展开所有节点,我该怎么做?plunker 中的更多详细信息.

I have recursive tree component and I would like to expand all nodes on click from parent component, how can I do this? More details in plunker.

Plunker

我说的是这个方法:

   expandAll(){
    console.log("expanded all");
  }

推荐答案

过了一会儿我想我明白了.我刚刚在 TreeComponent 中添加了一个 @Input() :

After a while I guess I figure it out. I just added one more @Input() in TreeComponent:

@Input() expandAll: boolean;

并将*ngIf递归条件替换为:

[hidden]="(!expanded[i] && !expandAll) || (expanded[i] && expandedAll)"

它需要做更多的工作(折叠所有内容并没有按照它应该的方式工作),但它可以按照我想要的方式工作.

Its need a bit more work (collapsing all doesnt work that how it should), but it works that how I wanted.

Plnker

这篇关于Angular2 递归树展开所有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆