首页 > 代码库 > ng 树形菜单
ng 树形菜单
代码地址:http://files.cnblogs.com/files/fxnet/%E5%8E%9F%E7%94%9Fjs%E6%8B%96%E6%8B%BD%EF%BC%88%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%EF%BC%89.rar
主要用到了ng的 ng-include跟指令 采用递归的方式可以无限进行遍历树结构。
<html ng-app="treeDemo"> <body> <div ng-controller="TreeController"> <folder-tree current-folder="folder"></folder-tree> </div> <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script> </body> </html>
<p ng-click="child(currentFolder)">{{currentFolder.name}}</p> <ul> <li ng-repeat="subfolder in currentFolder.children" ng-include="‘./tree.html‘" ng-init="currentFolder = subfolder"> </li> </ul>
<script> angular.module(‘treeDemo‘, []) .controller("TreeController", function ($scope) { $scope.child = function (item) { item.children = [{ name: item.name + "2EE"}]; console.log(item) } $scope.folder = { name: ‘techs‘, children: [ { name: ‘server-side‘, children: [ { name: ‘Java‘, children: [ { name: "J2EE" } ] }, { name: ‘Python‘ }, { name: ‘Node‘ } ] }, { name: ‘front-end‘, children: [ { name: ‘jQuery‘ }, { name: ‘Angular‘ }, { name: ‘React‘ } ] } ] } }) .directive("folderTree", function () { return { restrict: "E", scope: { currentFolder: ‘=‘ }, templateUrl: ‘./tree.html‘, link: function ($scope) { $scope.child = function (item) { console.log(item) item.children = [{ name: item.name + "2EE"}]; } } }; }); </script>
ng 树形菜单
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。