角度ng重复滤波器大于

时间:2015-03-23 10:43:58

标签: angularjs select filter ng-repeat minimum

我使用angular来创建搜索属性表单,并且我有一个包含大量卧室的选择框,如何创建更大的过滤器? (例如:选择2间卧室时,显示2间卧室以上的所有房产)

选择框:

<select class="form-control" 
        name="bedrooms" 
        ng-model="Bedrooms" 
        ng-options="property.data.SubType as (property.data.Bedrooms + ' Bedrooms ('+ property.count +')') for property in properties  | unique:'Bedrooms' | orderBy:'data.Bedrooms'">
        <option value="">Minimum Bedrooms</option>
</select>  

过滤器:

<tr ng-repeat="property in filtered = (properties | filterMultiple:{Address: Address, SubArea:SubArea, SubType:SubType} | filter:{Bedrooms:Bedrooms})|  orderBy:Address">  

这是我的JSFiddle

1 个答案:

答案 0 :(得分:2)

http://jsfiddle.net/odpw6c6q/43/

ng-options中使用ng-options="property.data.Bedrooms as代替ng-options="property.data.SubType as 因为data.Bedrooms是包含应存储在ng-model

中的卧室数量的属性

在范围内添加此功能

//Filter Function
    $scope.greaterThan = function(bedrooms) {
        return function(item) {                          
            if ( item['Bedrooms'] > bedrooms) {                
                return true;
            } else {                
                return false;
            }
        }
    };

ng-repeat中使用filter: greaterThan(Bedrooms)代替filter:{Bedrooms:Bedrooms}