如何在 ui-select 的 ng-model 中使用对象的 id 而不是整个对象
how to use id of object instead of whole object in ng-model of ui-select
使用 ui-select,我有人员名单,想通过这种方式在 ui-select
中显示:
(function() {
'use strict';
angular
.module('framework')
.controller('UserDetailController', UserDetailController);
function UserDetailController(BasePersonel) {
var vm = this;
vm.basePersonels = BasePersonel.all();
}
})();
<ui-select ng-model="vm.basePersonelId" >
<ui-select-match>
<span ng-bind="$select.selected.entityTitle"></span>
</ui-select-match>
<ui-select-choices repeat="item in (vm.basePersonels | filter: $select.search) track by item.id">
<span ng-bind="item.entityTitle"></span>
</ui-select-choices>
</ui-select>
但我想将所选对象的 id
设置为 vm.basePersonelId
而不是整个对象。
我该怎么做?
从这个
改变你的repeat
repeat="item in (vm.basePersonels | filter: $select.search) track by item.id"
至此:
repeat="item.id as item in (vm.basePersonels | filter: $select.search) track by item.id"
查看更多here
使用 ui-select,我有人员名单,想通过这种方式在 ui-select
中显示:
(function() {
'use strict';
angular
.module('framework')
.controller('UserDetailController', UserDetailController);
function UserDetailController(BasePersonel) {
var vm = this;
vm.basePersonels = BasePersonel.all();
}
})();
<ui-select ng-model="vm.basePersonelId" >
<ui-select-match>
<span ng-bind="$select.selected.entityTitle"></span>
</ui-select-match>
<ui-select-choices repeat="item in (vm.basePersonels | filter: $select.search) track by item.id">
<span ng-bind="item.entityTitle"></span>
</ui-select-choices>
</ui-select>
但我想将所选对象的 id
设置为 vm.basePersonelId
而不是整个对象。
我该怎么做?
从这个
改变你的repeat
repeat="item in (vm.basePersonels | filter: $select.search) track by item.id"
至此:
repeat="item.id as item in (vm.basePersonels | filter: $select.search) track by item.id"
查看更多here