过滤部分框不会删除空白点

时间:2014-07-10 18:11:51

标签: javascript jquery html angularjs

Fiddle

我无法过滤我正在处理的项目的部分框。理想情况下,第一个部分框将折叠以仅显示已过滤的选项,而只是将过滤的选项留空。 我的HTML是:

    <select class="files">
        <option class="{{file | types:type}}"  ng-repeat="file in mdFiles" path="{{file.path}}" >{{file | types:type}}</option>
    </select>

    <select class="filters" ng-model="type" >
        <option ng-model="type" ng-repeat="options in filters" value="{{options.filter}}">{{options.filter}}</option>

    </select>

和我的角度代码:

app.filter('types', function () {
    return function (input, type) {
       console.log("i.t: " + input.type + ",t: " + type);
       if(input.type == type || type == 'all')
          return input.name;
    }
});

1 个答案:

答案 0 :(得分:0)

我想你想要这样的东西。

http://jsfiddle.net/nXH5J/

您的过滤器

app.filter('types', function () {
    return function (files, type) {

        var filtered = [];
        angular.forEach(files, function(file) {
            if(file.type == type || type == 'all') {
             filtered.push(file);
           }
        });
        return filtered;
    }
    });

然后选择

<select class="files">
            <option ng-repeat="file in mdFiles | types:type"  path="{{file.path}}">{{file.name}}</option>
        </select>

您对数组应用过滤,并且该过滤器正在创建带有过滤选项的新数组。