Javascript 如何在angularjs中显示json

Javascript 如何在angularjs中显示json,javascript,json,angularjs,Javascript,Json,Angularjs,我需要帮助显示json,在angular js selector中谁的结构是这样的。我是一个新的角度和帮助显示作为一个下拉列表,使其成为一个可搜索的欢迎 [ { "id":1, "name":"something1", "displayName":"something1", "children":[ { "id":9, "name":"

我需要帮助显示json,在angular js selector中谁的结构是这样的。我是一个新的角度和帮助显示作为一个下拉列表,使其成为一个可搜索的欢迎

[

    {
        "id":1,
        "name":"something1",
        "displayName":"something1",
        "children":[
            {
                "id":9,
                "name":"something1Child1",
                "displayName":"something1/ something1Child1",
                "children":[
                ],
                "typeId":1,
                "parentId":1
            },
            {
                "id":10,
                "name":"something1Child2",
                "displayName":"something1 / something1Child2",
                "children":[
                ],
                "typeId":1,
                "parentId":1
            }
        ]
  }

  {
        "id":2,
        "name":"something2",
        "displayName":"something2",
        "children":[
        ]
  }

]

您只需要为孩子们重复一次嵌套ng

<span ng-repeat="something in somethings"> 
  <h3>{{ something.name }}</h3>
  <select>
    <option ng-repeat="child in something.children"> {{ child.name }}</option>
  </select>
</span>

{{something.name}
{{child.name}
我猜你想如何展示它们,但我希望它能给你一些想法

这是你想要的吗?它接受嵌套结构并从中生成平面结构。然后,它将使用该平面结构进行显示

<select ng-model="selected">
    <option ng-repeat="option in tree" ng-bind-html-unsafe="option.displayName" value="{{$index}}">{{ option.displayName }}</option>
</select>

$scope.tree = [];
function buildTree(data, depth) {
    for(d in data) {
        var c = angular.copy(data[d]); //copy object
        delete c['children'];  //we dont want to copy children
        c.displayName = Array(depth*4).join("&nbsp;") + c.displayName;
        $scope.tree.push(c);
        buildTree(data[d].children, depth+1);
    }
}
buildTree($scope.data, 0);

{{option.displayName}}
$scope.tree=[];
函数构建树(数据、深度){
对于(数据中的d){
var c=angular.copy(数据[d]);//复制对象
删除c['children'];//我们不想复制子对象
c、 displayName=数组(深度*4)。连接(“”+c.displayName;
$scope.tree.push(c);
构建树(数据[d]。子级,深度+1);
}
}
构建树($scope.data,0);

我使用了
ng bind html unsafe
,因为您希望将其显示为一棵树,我觉得最好是在嵌套选项之前添加空格,这是通过

完成的,您的代码的哪一部分遇到了问题?我在显示json时遇到了问题,就像下拉列表一样。我不知道怎么做。可能是使用ng选项或其他什么?可能是重复的我在这上面停留了16个多小时。就像我伤心一样,我是个新手。我让这个json显示在一个未排序的列表中,但我还需要一个选项来搜索该列表,类似于typeahead,我不知道如何执行该操作。@我知道如何显示json的第一级。我也需要孩子们来展示,我需要它像树一样展示。全部在下拉列表中。谢谢你的努力。