如果树折叠或展开,如何保持父项和子项顺序索引?

时间:2014-02-06 20:48:13

标签: angularjs

如果项目有子项目已折叠/展开,是否有任何方法可以按顺序编号顺序将项目保留在基于ng-repeat的树中?

我的意思是这样的:

扩展状态

Parent1                 (index value should be 0)
 -----  Child 1         (index value should be 1)
 -----  Child 2         (index value should be 2)
Parent 2                (index value should be 3)
Parent 3                (index value should be 4)
 ----   Child 1         (index value should be 5)
Parent 4                (index value should be 6)
 -----  Child 1         (index value should be 7)
 -----  Child 2         (index value should be 8)
 -----  Child 3         (index value should be 9)
 -----  Child 4         (index value should be 10)

same data when collapsed

Parent1                 (index value should be 0)
Parent 2                (index value should be 3)
Parent 3                (index value should be 4)
Parent 4                (index value should be 6)
 -----  Child 1         (index value should be 7)
 -----  Child 2         (index value should be 8)
 -----  Child 3         (index value should be 9)
 -----  Child 4         (index value should be 10)

最诚挚的问候,

1 个答案:

答案 0 :(得分:0)

这种情况下的数据结构如下所示:

parentTree = [];
parentTree[0].childs = [];

所以,ng-repeat应该处理三个​​。有可能吗?

如何使用ng-repeat迭代Tree?

所以ng-repeat应该处理ng-repeat =“parentTree中的父”和 如果是parent.childs> 0然后ng-repeat =“父母的孩子”

如何实现这个?