【问题标题】:angularJS + UI bootstrap typeahead: filter:$viewValue doesn't workangularJS + UI bootstrap typeahead: filter:$viewValue 不起作用
【发布时间】:2022-04-04 07:25:18
【问题描述】:

我无法让 filter:$viewValue 在输入前输入。 我显示了整个列表,突出显示了输入的字符。 我希望根据输入的字符过滤列表。

这里是一个笨蛋:http://plnkr.co/edit/X3C0fP52ZTi55LJtXfnu?p=preview

在我的实际项目中,我需要应用两个过滤器,如下所示。

<input autocomplete="off" 
  type="text" 
  placeholder="Selected Criteria"     
  ng-model="MgtCtrl.editActionData.selectedCriteria" 
  typeahead='criteria as criteria.name for criteria in MgtCtrl.criteriaList | criteriaByApplication:MgtCtrl.getTriggerApplication() | filter:$viewValue | orderBy:"name"'>

【问题讨论】:

标签: angularjs angular-ui-bootstrap typeahead


【解决方案1】:

如果你的集合项是一个对象,那么你需要指定过滤器应该考虑哪个属性。

根据您的示例,过滤器将如下所示:

| filter:{'name':$viewValue}

由于您显示的是 name 属性,它可能是您要过滤的名称,但我可能错了。所以你需要根据你的上下文来充分利用它。

参考资料: https://docs.angularjs.org/api/ng/filter/filter

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 2014-10-08
    相关资源
    最近更新 更多