gpt4 book ai didi

javascript - 以编程方式选择的选项未在 ui-select 中突出显示

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:04:16 25 4
gpt4 key购买 nike

Angular 版本: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>

问题是当以编程方式选择 p1 时

p1 对象未在 ui-select 下拉列表中突出显示。

输出是:

enter image description here

http://plnkr.co/edit/3mrECwGJbz2UYcrDiCha?p=preview

enter image description here

最佳答案

这是由于 AngularJS 1.3.1 中的以下更改:

$observe: check if the attribute is undefined

Ui-select 使用 $observeresetSearchInput 设置默认值:

attrs.$observe('resetSearchInput', function() {
var resetSearchInput = scope.$eval(attrs.resetSearchInput);
$select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true;
});

但是由于上面提到的更改以及 resetSearchInput 未定义,因此永远不会执行观察者函数。

现在要解决它,请将以下属性添加到您的 ui-select 元素:

reset-search-input="'false'"

演示: http://plnkr.co/edit/M0pXrN3n6CBjjoJXS4df?p=preview

关于javascript - 以编程方式选择的选项未在 ui-select 中突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28146868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com