0

我正在尝试创建一个多选下拉菜单。

我看到我可以使用该ng-options指令基本上比较两个数据集,将任何匹配选项设置为selected.

这是我拥有的两个系列:

// Full list of possible recipients and the different types

reference = {
  "AddressBook": [
    {
      "ID": 1,
      "FullName": "Angela Williams",
      "IsActive": true,
      "SendType": null,
      "Email": "awilliams@yamia.com"
    },
    {
      "ID": 2,
      "FullName": "Jerry Schmidt",
      "IsActive": true,
      "SendType": null,
      "Email": "jschmidt@cogibox.mil"
    },
    {
      "ID": 3,
      "FullName": "Judy Olson",
      "IsActive": true,
      "SendType": null,
      "Email": "jolson@buzzdog.gov"
    },
    {
      "ID": 4,
      "FullName": "Sara Griffin",
      "IsActive": true,
      "SendType": null,
      "Email": "sgriffin@yoveo.org"
    }
  ],
  "SendTypes": [
    {
      "ID": 1,
      "Value": "To"
    },
    {
      "ID": 2,
      "Value": "CC"
    },
    {
      "ID": 3,
      "Value": "BCC"
    }
  ]
}

// Selected recipients

currentNotification.TO = [
  {
    "Email": "awilliams@yamia.com",
    "FullName": "Angela Williams",
    "ID": 1, 
    "IsActive": true,
    "SendType": "To"
  },
  {
    "Email": "sgriffin@yoveo.org",
    "FullName": "Sara Griffin",
    "ID": 4, 
    "IsActive": true,
    "SendType": "To"
  }
]

我尝试用于标记的内容:

<div class="form-group" ng-repeat="sendType in reference.SendTypes">
  <label for="">{{sendType.Value}}:</label>
  <select class="form-control" name="" id="recipients{{sendType}}" ng-multiple="true" multiple ng-model="currentNotification[(sendType.Value).toUpperCase()]" ng-options="recipient.FullName for recipient in reference.AddressBook | orderBy: 'FullName'"></select>
</div>

使用该标记,我最终为每个 SendType(To、CC、BCC)创建了一个 .form-group。在每一个中,我都有正确的标签显示(sendType.Value)。多选显示并为地址簿中的每个条目重复一个选项。它也正确排序。不幸的是,没有选择任何内容。

做一些研究ng-options,似乎我的selected集合可能需要是一个字符串数组而不是一个对象数组。真的吗?

奇怪的是,如果我手动选择一些收件人,模型会按应有的方式更新:

BCC = [
  { ... },
  { ... },
  { ... },
  { 
    "ID": 3,
    "FullName": "Judy Olson",
    "IsActive": true,
    "SendType": null,
    "Email": "jolson@buzzdog.gov"
  }
]

非常感谢您对此的任何帮助。目前它把我拖到了最后期限之后。如果有人想要小提琴之类的,请告诉我。再次感谢!

4

0 回答 0