Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 有棱角的孩子在孩子里面_Javascript_Json_Angularjs - Fatal编程技术网

Javascript 有棱角的孩子在孩子里面

Javascript 有棱角的孩子在孩子里面,javascript,json,angularjs,Javascript,Json,Angularjs,我对angularJs中的递归有问题 我想重复JSON文件中的所有名称: 以下是我的JSON文件结构: var data = { "id": "580", "name": "test", "status": "ACTIVE", "parentId": null, "children": [ { "id": "581", "name": "test 2", "status

我对angularJs中的递归有问题

我想重复JSON文件中的所有名称: 以下是我的JSON文件结构:

var data = {
    "id": "580",
    "name": "test",
    "status": "ACTIVE",
    "parentId": null,
    "children": [
        {
            "id": "581",
            "name": "test 2",
            "status": "ACTIVE",
            "parentId": "580",
            "children": [{
                "id": "594",
                "name": "test 3",
                "status": "ACTIVE",
                "parentId": "581",
                "children": []
            }]
        }
    ]
}

我只想知道如何使ng在children中重复children?

为了递归使用ng模板,您应该使用ng模板

<script type="text/ng-template" id="exampleTree">
{{ x.name }}
    <ul ng-if="x.children">
        <li ng-repeat="x in x.children" ng-include="'exampleTree'">           
        </li>
    </ul>
</script>

{{x.name}
要使用并运行此模板,请执行以下操作:

<ul>
    <li ng-repeat="x in data" ng-include="'exampleTree'"></li>
</ul> 

您可以将ng repeat与模板一起使用,以便尽可能多地使用数据。以下是一个例子:

var-app=angular.module('app',[]);
应用程序控制器('MainCtrl',函数($scope){
$scope.child={
“id”:“580”,
“名称”:“测试”,
“状态”:“活动”,
“parentId”:空,
“儿童”:[{
“id”:“581”,
“名称”:“测试2”,
“状态”:“活动”,
“家长ID”:“580”,
“儿童”:[{
“id”:“594”,
“名称”:“测试3”,
“状态”:“活动”,
“家长ID”:“581”,
“儿童”:[]
}]
}]
}
});

{{child.name}

有多少级别的儿童?据我所知,你不能递归地使用
ng repeat
。那些孩子可以动态地生成。所以我不知道应该有多少人!google
angular recursive tree
应该在那里找到很多解决方案、模块、指令等
{children:[{children:{children:[{…}]}]}
。子对象是数组还是对象?