Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度UI select2阵列与对象是否可能?_Javascript_Angularjs_Jquery Select2_Angular Ui - Fatal编程技术网

Javascript 角度UI select2阵列与对象是否可能?

Javascript 角度UI select2阵列与对象是否可能?,javascript,angularjs,jquery-select2,angular-ui,Javascript,Angularjs,Jquery Select2,Angular Ui,有没有一种简单的方法可以将选项作为数组中的对象?例如: $scope.search.categories = [{id: '1',name: 'first'},{id: '2',name: 'last'}]; <select ui-select2 ng-model="search.categories" multiple style="width:300px" data-placeholder="select category"> <option ng-repeat="c

有没有一种简单的方法可以将选项作为数组中的对象?例如:

$scope.search.categories = [{id: '1',name: 'first'},{id: '2',name: 'last'}];

<select ui-select2 ng-model="search.categories" multiple style="width:300px" data-placeholder="select category">
  <option ng-repeat="category in search.categories" value="{{category}}">{{category.name}}</option>

</select>
$scope.search.categories=[{id:'1',name:'first'},{id:'2',name:'last'}];
{{category.name}

还是我完全错了?

请查看我制作的演示:

如果希望所选项目成为对象,请使用


演示向您展示了4种不同的方法来执行uiSelect2

是否有任何方法可以声明性地执行此操作?此库非常不推荐使用。我建议改用
ui-select
,或者使用其他维护性更强、更轻的解决方案。