简体   繁体   中英

JavaScript - ui-select and objects

I have a simple list of objects that I am trying to integerate to AngularJS's ui-select .

Here is the object I am trying to use <ui-select> with:

[
  {
    "getGroupsRes": {
      "groups": [
        {
          "groupID": "1",
          "applicationID": "1",
          "groupDesc": "Members",
          "groupDesc2": "MEMBERS_US_1"
        },
        {
          "groupID": "2",
          "applicationID": "1",
          "groupDesc": "Administrators",
          "groupDesc2": "ADMINS_US_100"
        },
        {
          "groupID": "3",
          "applicationID": "1",
          "groupDesc": "Moderators",
          "groupDesc2": "MODS_US_50"
        },
        {
          "groupID": "4",
          "applicationID": "1",
          "groupDesc": "Distinguished Members",
          "groupDesc2": "DMEMBS_US_50"
        },
        {
          "groupID": "5",
          "applicationID": "1",
          "groupDesc": "Elected Members",
          "groupDesc2": "EMEMS_US_75"
        },
        {
          "groupID": "6",
          "applicationID": "1",
          "groupDesc": "Staffed Officials",
          "groupDesc2": "SOFF_US_25"
        },
        {
          "groupID": "7",
          "applicationID": "1",
          "groupDesc": "Janitors",
          "groupDesc2": "JANS_US_50"
        }
      ]
    }
  }
]

and here is a live demo of the plunker: http://plnkr.co/edit/ANJcORDfoKYQ3k5X1pzs?p=preview

I think the problem comes down to me not being able to reference my objects correctly.I see no error in the console log though.What am I doing wrong?

Your $scope.groups variable is not an array of groups. It's an array with one element that contains the field "getGroupsRes", which contains the field "groups". So, until you clean up the data structure a bit, you can access it with the following:

repeat="group in groups[0].getGroupsRes.groups"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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