简体   繁体   English

angularJS $ http.get()请求复杂的JSON输出

[英]angularJS $http.get() request on a complicated JSON output

I have a PHP that gives out an output in the form JSON code like this : 我有一个PHP,它以JSON代码的形式给出一个输出,如下所示:

{
    "data": {
        "groups": {
              "admin": [
                { "loginname" : user1 },
                { "loginname" : user2 }
              ],
              "group1" : [
                { "loginname" : user1 },
                { "loginname" : user2 }
              ]
            }
        },
    "status":"success"
}

Basically each loginname corresponds to a group name which is a variable (admin and group 1 in this case). 基本上每个loginname对应一个组名,它是一个变量(在本例中为admin和group 1)。 How will I access the list of all groups from this output? 如何从此输出中访问所有组的列表? The key of my php array is itself a variable making it difficult. 我的php数组的关键本身就是一个让它变得困难的变量。 Here is the link to the PHP : https://gist.github.com/raghunayyar/cf8d29d9e4ccc0423125 . 以下是PHP的链接: https//gist.github.com/raghunayyar/cf8d29d9e4ccc0423125 Ask me if any more info is required. 问我是否需要更多信息。 :) :)

Assuming you store the JSON response data value in a variable called data , it sounds like you just need something like this in your view: 假设您将JSON响应data值存储在名为data的变量中,听起来您在视图中只需要这样的内容:

<ul>
  <li ng-repeat="(group, users) in data.groups">
    <p>Group: {{group}}</p>
    <ul>
      <li ng-repeat="user in users">{{user}}</li>
    </ul>
  </li>
</ul>

This would print a list of groups with a sub-list of users. 这将打印具有用户子列表的组列表。 Here is a link to the Angular documentation on the ng-repeat directive. 以下是ng-repeat指令的Angular文档的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM