嵌套NG-重复angularjs
我有一个价值一样,我的问题是我不知道有多少嵌套在该虚拟阵列对象,因此如何使用NG-重复打印所有虚拟阵列对象嵌套NG-重复angularjs
demo: [{
id: 1,
dummy: [
{
id: 1,
dummy: [
{
id: 1,
dummy: [
{
id: 1
}
]
}
]
}
]
}]
试喜欢这个。因为这样回答:How to put ng-repeat inside ng-repeat for n number of times 和How can I make recursive templates in AngularJS when using nested objects?
var app = angular.module("app", []);
app.controller('mainCtrl', function($scope){
$scope.demo = [{
id: 1,
dummy: [
{
id: 1,
dummy: [
{
id: 1,
dummy: [
{
id: 1,
dummy: [
{
id: 1,
dummy:[]
}
]
}
]
}
]
}
]
}]
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.2/css/font-awesome.min.css" rel="stylesheet"/>
<div ng-app="app" ng-controller="mainCtrl">
<script type="text/ng-template" id="dummy.html">
<ul>
<li ng-repeat="d in demo" >
<div >{{d.id}}</div>
<div ng-show="d.dummy.length" ng-include=" 'dummy.html' " onload="demo = d.dummy"></div>
</li>
</ul>
</script>
<div ng-include=" 'dummy.html'" ></div>
</div>
@Walfrat但我在Chrome上测试了这个! –
好吧,我完全不知道为什么,现在它显示...我删除了旧评论说'不工作',所以人们不会停下来。 – Walfrat
谢谢你的工作正常我现在接受你的答案,但我有一个问题如果我需要以降序显示它意味着最后一个虚拟数组对象首先显示。可能吗? –
看到这个漂亮的答案。 http://stackoverflow.com/questions/37108946/how-to-put-ng-repeat-inside-ng-repeat-for-n-number-of-times/37109091#37109091 –
它只处理两个级别 –
不是当然,但你可以创建一个指令来打印当前元素并用新的虚拟值调用它自己。 – Rajesh