我在角度js中使用了ui.select我已经成功插入了所选的多个选项,但现在当我在更新时如何在ui.select中选择我使用过ng-selected但它无效的ui.select中的选定值。
<ui-select multiple ng-model="items.itemOptions" theme="bootstrap"
sortable="true" close-on-select="false">
<ui-select-match placeholder="Select Modules...">{{$item.module_desc}}</ui-select-match>
<ui-select-choices repeat="itemOptions in itemOption">
<div ng-bind-html="itemOption.id | highlight: $select.search" ng-selected="selectSource(itemOption.id)"></div>
<small>
{{itemOption.name}}
</small>
</ui-select-choices>
我的控制器中的selet功能
$scope.selectSource = function(id)
{
console.log('id'+id);
var arr = $scope.selectedOptions;
if (arr) {
angular.forEach(arr, function (value, key) {
console.log('sel-id'+value.id);
if (id == value.module_id)
console.log('sel-opt-id'+value.id);
return 'selected';
});
}
}
selectedOptions array =
[{id: "1"}, {id: "2"}]
我的问题是如何使用angular js select2指令在ui.selct中显示所选选项。
答案 0 :(得分:1)
即使我遇到类似的问题,我也想编辑选定的多个选项。
解决方案是当您使用多个选项处理 ui-select 时, ng-model 应始终以.selected
结束
相应地更改第一行:
<ui-select multiple ng-model="items.itemOptions.selected" theme="bootstrap"
sortable="true" close-on-select="false">
查看它的维基:https://github.com/angular-ui/ui-select/wiki/ui-select