【问题标题】:Angular UI Bootstrap Typeahead by object propertiesAngular UI Bootstrap Typeahead 按对象属性
【发布时间】:2018-09-24 00:12:05
【问题描述】:

我有一个类似的对象(模仿地图):

$scope.vehicles = {
   1:{id:1, model:'Sedan'},
   2:{id:2, model:'SUV'},
   3:{id:3, model:'Van'}
}

我需要在 ui bootstrap 的 typeahead 中使用属性值(通过“模型”属性保存过滤)

下一个变体不起作用:

<input type="text" ng-model="vehicle"
   uib-typeahead="vehicle as vehicle.model for (id, vehicle) in vehicles | filter:{model:$viewValue} | limitTo:10">

【问题讨论】:

    标签: angularjs angular angular-ui-bootstrap


    【解决方案1】:

    使用对象属性列表需要特殊功能

    $scope.getVehicleList = function () {
       return Object.values($scope.vehicles);
    }
    

    Typeahead 元素:

    <input type="text" ng-model="vehicle"
           uib-typeahead="vehicle as vehicle.model for vehicle in getVehicleList() | filter:{model:$viewValue} | limitTo:10">
    

    【讨论】:

      猜你喜欢
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2017-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多