[英]how select the selected value in select2 ui.select in angularjs with ng-selected
我已經在angular js中使用了ui.select我已經成功地插入了所選的多個選項,但是現在當我進行更新時,我將如何在ui.select中選擇所選的值,我已經使用了ng-selected,但是無法正常工作。
<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數組=
[{id: "1"}, {id: "2"}]
我的問題是如何使用angular js select2指令在ui.selct中顯示選定的選項。
即使遇到了類似的問題,我也想編輯選擇的多個選項。 解決方案是,當您使用多個選項進行ui-select時 , ng-model應該始終以.selected
相應地更改第一行:
<ui-select multiple ng-model="items.itemOptions.selected" theme="bootstrap"
sortable="true" close-on-select="false">
查看它的Wiki: https : //github.com/angular-ui/ui-select/wiki/ui-select
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.