0

I have a PHP that gives out an output in the form JSON code like this :

{
    "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). 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. Here is the link to the PHP : https://gist.github.com/raghunayyar/cf8d29d9e4ccc0423125. Ask me if any more info is required. :)

6
  • Can you let us know what is the final value that you are expecting? I am confused with the structure of your model - so maybe you could just let us know what value you are expecting... Commented Jun 22, 2013 at 9:31
  • I want to get the list of groups(admin, group1), and list of users belonging to that particular group(user1,user 2 for both the groups.). Commented Jun 22, 2013 at 9:45
  • Where do you want to get it? As in, do you want this information in your controller or in your view? Commented Jun 22, 2013 at 9:58
  • ohh, okay view, basically a list like <li ng-repeat = "group in groups"> I have already defined controllers and the remaining stuff. :) Commented Jun 22, 2013 at 10:03
  • you want to create ul list with all groups in it? Commented Jun 22, 2013 at 10:06

1 Answer 1

2

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:

<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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.