javascript - ui-select 将数组元素显示为下拉列表中的选项

标签 javascript angularjs drop-down-menu ui-select angular-ui-select

我正在使用 ui-select 如下。

<ui-select id="ItemId" ng-model="ctrl.ItemId" theme="bootstrap"
                       ng-disabled="ctrl.DownDisabled" required>
                <ui-select-match placeholder={{ctrl.Placeholder}}>{{$select.selected.item}}
                </ui-select-match>
                <ui-select-choices
                        repeat="item in ctrl.owners.components">
                    <div ng-bind-html="item | highlight: $select.search"></div>
                </ui-select-choices>
                <ui-select-no-choice>
                    No features were found
                </ui-select-no-choice>
            </ui-select>

它正在迭代的 JSON 是

ctrl.owners = {
            value : 123,
            teamName : ABC,
            components : [a,b,c]
            };

但是 UI 下拉菜单显示“未找到任何功能”。什么问题。我的目标是将 组件 显示为下拉列表中的单独选项。 AFAIK 这需要通过在 ui-select-choices 中使用嵌套重复以某种方式完成。我该怎么做?

最佳答案

<div class="form-group ">
   <ui-select ng-model="person.selected" theme="bootstrap">
   <ui-select-match placeholder="Select or search a person in the list...">{{$select.selected.name}}</ui-select-match>
   <ui-select-choices repeat="item in people | filter: $select.search">
       <div ng-bind-html="trustAsHtml((item.name | highlight: $select.search))"></div>
        <small ng-bind-html="trustAsHtml((item.email | highlight: $select.search))"></small>
   </ui-select-choices>
   </ui-select>
</div>

$scope.people = [
{ name: 'Adam',      email: 'adam@email.com',      age: 12, country: 'United States' },
{ name: 'Amalie',    email: 'amalie@email.com',    age: 12, country: 'Argentina' }];

你可以像这样使用它会起作用。 这里的 trustAsHtml 是方法。

  $scope.trustAsHtml = function(value) {
    return $sce.trustAsHtml(value);
  };

关于javascript - ui-select 将数组元素显示为下拉列表中的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40398377/

相关文章:

javascript - IE 不在 div 上显示背景颜色

javascript - ngResource 导致显示错误

angularjs - 未调用 Angular Typescript Controller 构造函数

html - css 下拉菜单不会在悬停时保持打开状态

javascript - MVC - html.dropdownlist - 直接调用 javascript 或 Controller /方法?

javascript - 同一域上的访问控制允许来源问题

javascript - SVG 调整大小有这么难吗?我缺少什么?

javascript - Angular UI网格无法对具有行索引的列进行排序

java - JPA 创建现有实体的精简实体版本

Spring MVC 和 Thymeleaf - 如何检索下拉菜单中选定的值