Javascript AngularJS:形成树结构
是否可以如下图所示在AngularJS中创建树结构 从现场拍摄的图像: 我的HTML代码 }] 我的输出 我已经检查过了,但对我的要求来说太复杂了。Javascript AngularJS:形成树结构,javascript,html,angularjs,Javascript,Html,Angularjs,是否可以如下图所示在AngularJS中创建树结构 从现场拍摄的图像: 我的HTML代码 }] 我的输出 我已经检查过了,但对我的要求来说太复杂了。 请让我知道是否有任何第三方库可以为我提供一个简单的树结构,它可以折叠和扩展。请参考,这可能会帮助您了解一些想法。经过大量搜索,找到了解决方案 查看演示 下载源代码 希望这对其他人有帮助。您只需要一条指令,答案就在StackOverflow上。这是一条指令,您只需修改已接受答案中的模板,然后点击您的uncle@CallumLinington我让树
请让我知道是否有任何第三方库可以为我提供一个简单的树结构,它可以折叠和扩展。请参考,这可能会帮助您了解一些想法。经过大量搜索,找到了解决方案 查看演示 下载源代码
希望这对其他人有帮助。您只需要一条指令,答案就在StackOverflow上。这是一条指令,您只需修改已接受答案中的模板,然后点击您的uncle@CallumLinington我让树的结构运转起来了。我想要一个合适的UI,正如我在第一张图中所示。你提供的链接看起来很棒。但是,你是否遇到了我在第一张图片中给出的那个。它有虚线。链接不再工作了
<body ng-controller="myCtrl" data-ng-init="init()">
<input type="text" ng-model="queryColumnName">
<div id="treeNav">
<ul id="tree">
<li ng-repeat="component in components | filter: queryColumnName" ng-include="'objectTree'"></li>
</ul>
</div>
<script src="angular.min.js" type="text/javascript"></script>
<script type="text/ng-template" id="objectTree">
{{ component.ViewName }}
<ul ng-if="component.ViewComponent">
<li ng-repeat="component in component.ViewComponent | filter: queryColumnName" ng-include="'objectTree'">
</li>
</ul>
</script>
<script type="text/javascript">
myApp = angular.module('myApp', []);
myApp.controller('myCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.init = function () {
$http.get('data.json').success(function (data) {
$scope.components = data;
}).error(function (data) {
console.log('Error');
});
};
}]);
</script>
</body>
[{
"ViewName": "BASE_VIEW",
"ViewComponent": [{
"ViewName": "BASE_COMP2",
"ViewComponent": [{
"ViewName": "COMP_COMP2",
"ViewComponent": [{
"ViewName": "FND_USER",
"ViewComponent": []
}]
}, {
"ViewName": "EIS_RS_REPORTS",
"ViewComponent": [{
"ViewName": "EIS_RS_REPORT_COLUMNS",
"ViewComponent": []
}, {
"ViewName": "EIS_RS_REPORT_COND_HEADERS",
"ViewComponent": [{
"ViewName": "EIS_RS_REPORT_COND_DETAILS",
"ViewComponent": []
}]
}, {
"ViewName": "EIS_RS_REPORT_PARAMETERS",
"ViewComponent": []
}, {
"ViewName": "EIS_RS_VIEWS",
"ViewComponent": [{
"ViewName": "EIS_RS_VIEW_COLUMNS",
"ViewComponent": []
}]
}]
}]
}, {
"ViewName": "BASE_COMP1",
"ViewComponent": [{
"ViewName": "EIS_RS_REPORTS",
"ViewComponent": [{
"ViewName": "EIS_RS_REPORT_COLUMNS",
"ViewComponent": [{
}]
}, {
"ViewName": "EIS_RS_REPORT_COND_HEADERS",
"ViewComponent": [{
"ViewName": "EIS_RS_REPORT_COND_DETAILS",
"ViewComponent": []
}]
}, {
"ViewName": "EIS_RS_REPORT_PARAMETERS",
"ViewComponent": []
}, {
"ViewName": "EIS_RS_VIEWS",
"ViewComponent": [{
"ViewName": "EIS_RS_VIEW_COLUMNS",
"ViewComponent": []
}]
}]
}]
}]