角度版本:AngularJS v1.3.6 http://github.com/angular-ui/ui-select:版本:0.8.3
var p1 = {name:' Ramesh',email:' Ramesh@email.com' ;, age:99};
$scope.people = [
{ name: 'Amalie', email: 'amalie@email.com', age: 12 },
{ name: 'Wladimir', email: 'wladimir@email.com', age: 30 },
{ name: 'Samantha', email: 'samantha@email.com', age: 31 },
{ name: 'Estefanía', email: 'estefanía@email.com', age: 16 },
{ name: 'Natasha', email: 'natasha@email.com', age: 54 },
{ name: 'Adrian', email: 'adrian@email.com', age: 21 },
p1
];
$scope.people.selected = p1 ;
HTML :
<ui-select class="full-width-select select" ng-model="people.selected" theme="select2">
<ui-select-match allow-clear="false">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="person in people | filter:$select.search">
<div ng-bind-html="person.name | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
&#13;
问题是以编程方式选择p1
p1对象未在ui-select下拉列表中突出显示。
输出是:
http://plnkr.co/edit/3mrECwGJbz2UYcrDiCha?p=preview
答案 0 :(得分:5)
这是由于AngularJS 1.3.1 :
中的以下变化$observe: check if the attribute is undefined
Ui-select使用$observe
为resetSearchInput
设置默认值:
attrs.$observe('resetSearchInput', function() {
var resetSearchInput = scope.$eval(attrs.resetSearchInput);
$select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true;
});
但是由于上面提到的更改以及resetSearchInput
未定义,因此观察器函数永远不会被执行。
现在要解决它,请将以下属性添加到ui-select元素:
reset-search-input="'false'"