【问题标题】:How to use typeahead-on-select in Angular JS?如何在 Angular JS 中使用 typeahead-on-select?
【发布时间】:2015-06-22 19:55:19
【问题描述】:

我使用来自引导 Angular JS 的 typeahead-on-select。 现在我已经编写了 HTML 代码:

<input type="text" ng-model="data.country[formData.country]" placeholder="Select country..." typeahead-on-select="onSelect($item, $model, $label)" typeahead="stuff as stuff.name for stuff in countries | filter:{name: $viewValue} | orderBy:stuff.name" aria-expanded="false" aria-owns="typeahead-16-5649">

当我在此输入上输入符号 a 时,我会得到自动完成未排序的结果,而国家/地区则没有从此符号命名。我做错了什么?

【问题讨论】:

    标签: angularjs bootstrap-typeahead angular-ui-typeahead


    【解决方案1】:

    当我们提前使用角度类型时,我们需要使用自定义过滤器函数来操作列表并根据自定义过滤器中编写的代码返回建议。

    typeahead="state as state.code +' - '+ state.name for state in Item|      filter:$viewValue:customFilterFunction" 
    

    这里customeFilter函数是在控制器内部定义的,它以所需的顺序返回建议列表。

    $scope.customFilterFunction = function(state,value){
    
        return state;
    
    }
    

    我们可以编写任何逻辑并根据我们的要求对建议进行排序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多