Javascript 在angularjs中动态添加过滤器选项

Javascript 在angularjs中动态添加过滤器选项,javascript,angularjs,angularjs-filter,Javascript,Angularjs,Angularjs Filter,您好,我有一个小项目,我想从多个动态添加的文本字段执行搜索 以下是我添加搜索字段的方式: <div class="form-group" ng-repeat="choice in choices"> <button ng-show="showAddChoice(choice)" ng-click="addNewChoice()">Add another choice</button> <input type="text" ng-mod

您好,我有一个小项目,我想从多个动态添加的文本字段执行搜索

以下是我添加搜索字段的方式:

<div class="form-group" ng-repeat="choice in choices">
     <button ng-show="showAddChoice(choice)" ng-click="addNewChoice()">Add another choice</button>
     <input type="text" ng-model="choice.name" name="" placeholder="Search criteria">
</div>

添加另一个选项
稍后我有一张带有ng repeat的表格,这是这一部分:

    <tr ng-repeat="todo in todos | filter: {filter from all fields}">
     .......
    </tr>

.......

我想做的是使用所有动态添加的搜索字段过滤内容。

您必须创建自己的过滤器来处理该问题。我已经让你开始了

        $scope.myFilter = function(input){
            for(var key in input){
                for(var x = 0; x < $scope.choices.length; x++){
                    if(input[key] == $scope.choices[x].name){
                     return true;   
                    }
                }
            }
            return false;
        }
$scope.myFilter=函数(输入){
for(输入中的var键){
对于(变量x=0;x<$scope.choices.length;x++){
if(输入[key]=$scope.choices[x].name){
返回true;
}
}
}
返回false;
}

以下是输出的JSFIDLE:

不要使用过滤器,而是自己在控制器中进行过滤。是最新的解决方案。在第一个文本框中,将choice1替换为“some”,您将看到todo显示为文本“some stuff”

请参阅下面的相关部分。有关详细信息,请参见小提琴

        $scope.$watch('choices', function(newValue) {
            $scope.DisplayedTodos = [];
            // Filter items here and push to DisplayedTodos. Use DisplayedTodos to display todos
        }, true);

你能为此提交一份JSFIDLE吗。我还没有测试过它,但是尝试一下ng repeat=“todo in todos | filter:choices”,它可能会工作。无过滤器:选项不起作用:/YEs,但这仍然不能满足我的需要。我需要通过第一个过滤器过滤的内容,这些结果将通过第二个、第三个过滤器再次过滤。您好,您只需要调整$watch中的代码,以您希望的方式过滤数据。我可以更改代码并为您执行,但这并不是stackoverflow.com的目的。