我想使用angular-ui ui.select来填充a multiple dropdown field.我想将选定的对象传递给ng-model并将其映射到我的选项,包含相同结构的对象,但不是来自同一个源:
<div ng-repeat="training in trainings">
<form class="form-horizontal" role="form">
<ui-select multiple ng-model="training.skills" theme="select2" ng-disabled="disabled">
<ui-select-match placeholder="Wähle Skills...">{{$item.name}}</ui-select-match>
<ui-select-choices group-by="skillTypeGrp" repeat="skill.id as skill in skills | filter: $select.search">
<span>{{skill.name}}</span>
</ui-select-choices>
</ui-select>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
带有示例培训的trainings列表ng-repeat如下所示:
[{"description": "",
"skills": [{"type": "tech",
"name": "C",
"id": 194}],
"id": 1,
"name": "Test"}]
Run Code Online (Sandbox Code Playgroud)
我的skills列表ui-select-choices包含与以下相同的数据结构training.skills:
[{"type": "tech",
"name": "C#",
"id": 194},
{"type": "tech",
"name": "Java",
"id": 197},
...]
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用.ui-select清空我training.skills,给我一个空白的选择字段.我知道angularjs无法映射这些对象,如果它们不是来自同一个数组,就像这篇博文中所述.它建议使用 …