gpt4 book ai didi

javascript - 为多个字段过滤 angular-ui typeahead autocomplete

转载 作者:行者123 更新时间:2023-11-29 19:35:37 25 4
gpt4 key购买 nike

我有一个 snippet in plunker .我尝试过滤两个字段的结果(在 OR 条件下)

typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue,country:$viewValue}"

代替当前

typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}"

条件应用为 AND term,但我需要 OR term

最佳答案

您可以创建自定义过滤器:

angular.module('plunker')
.filter('custom', function () {
return function(inputArray, args) {
var outputArray = [];
// Filtering logic below:
angular.forEach(inputArray, function (item) {
if (item.name.indexOf(args.viewValue) !== -1 || item.country.indexOf(args.viewValue) !== -1) {
outputArray.push(item);
}
});
return outputArray;
};
});

在这里查看工作插件: http://plnkr.co/edit/4s2ZxOokiXw9uMG5r75

您可以在此处找到用于创建自定义过滤器的文档:https://docs.angularjs.org/guide/filter#creating-custom-filters

关于javascript - 为多个字段过滤 angular-ui typeahead autocomplete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25244663/

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