ng-table filterFn在一列上

时间:2015-11-20 17:19:46

标签: javascript angularjs underscore.js ngtable

我一直在使用ng-table使用underscore.js创建带有自定义过滤器的表。过滤器有效,但我只想在一列上应用此过滤器,在所有其他列上,默认过滤器就可以了。

目前这就是我所拥有的:

function testEngineerFilter(data, filterValues) {
            if (filterValues.testEngineer == null)
                // Return the default filter?
            return _.filter(data, function(testCase) {
                return _.some(testCase.testEngineers, function(testEngineer) { return testEngineer.id === filterValues.testEngineer; })
                    || _.some(testCase.preAssignedTestEngineers, function(testEngineer) { return testEngineer.id === filterValues.testEngineer; });
            });
        }

我想我应该能够在if语句之后返回默认过滤器,但我不知道它位于何处。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

今天早上想出来。这就是我的用途:

function testEngineerFilter(data, filterValues) {
            if (filterValues.testEngineer != null) {
                data = _.filter(data, function(t) {
                    return _.some(t.testEngineers, function(te) { return te.id === filterValues.testEngineer; })
                        || _.some(t.preAssignedTestEngineers, function(te) { return te.id === filterValues.testEngineer; });
                });
            }

            // Remove testEngineer since it was filtered already
            delete filterValues.testEngineer;
            data = $filter('filter')(data, filterValues);

            return data;
        }