简体   繁体   English

JavaScript-用户界面选择和对象

[英]JavaScript - ui-select and objects

I have a simple list of objects that I am trying to integerate to AngularJS's ui-select . 我有一个简单的对象列表,试图将其整数化为AngularJS的ui-select

Here is the object I am trying to use <ui-select> with: 这是我尝试将<ui-select>与以下对象一起使用的对象:

[
  {
    "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 这是the客的现场演示: 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. 您的$ scope.groups变量不是组数组。 It's an array with one element that contains the field "getGroupsRes", which contains the field "groups". 它是一个数组,其中一个元素包含字段“ getGroupsRes”,其中包含字段“ 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"

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

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