You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
工作中我们经常要遍历多层数据,如果数据是已知层级的话,用 ng-repeat 就搞定了,要是数据深度是无限的呢,或者我们要实现一个无限层级的 tree 的时候,该怎么办?
答案是使用 ng-include 指令递归模板
Example
HTML
<!DOCTYPE html><html><headlang="en"><metacharset="UTF-8"><title></title><linkhref="../../vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"/><linkhref="../../vendor/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet"/></head><bodyng-app><divng-controller="treeController" class="container"><divclass="row"><h2>ng-repeat recursive list example</h2><ul><ling-repeat="item in tree" ng-include="'treeItem'"></li></ul></div></div><scriptsrc="../../vendor/angularjs/angularjs.js"></script><scriptsrc="treeList.js"></script><scripttype="text/ng-template" id="treeItem">{{item.id}}---{{item.name}}<ulng-if="item.children"><ling-repeat="item in item.children"ng-include="'treeItem'"></li></ul>
</script></body></html>
AngularJS recursive templates
http://benfoster.io/blog/angularjs-recursive-templates
http://www.cnblogs.com/kuangliu/p/4146705.html
Example
HTML
treeList.js
Angular Tree Grid(自己实现)
通过Angular自定义Filter,实现复杂Tree数据遍历(复杂数据参见上面的例子)和过滤(对expend数据过滤)
Example:
http://jsfiddle.net/hjzheng/78jz0mrL/ (翻墙)
The text was updated successfully, but these errors were encountered: