问题
I'm using angular to create a search property form, and I've got a select box with amount of bedrooms, how can I create a greater then filter? (for example: when 2 bedrooms selected, display all properties with 2 bedrooms or more)
The select box:
<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>
And the filter:
<tr ng-repeat="property in filtered = (properties | filterMultiple:{Address: Address, SubArea:SubArea, SubType:SubType} | filter:{Bedrooms:Bedrooms})| orderBy:Address">
This is my JSFiddle
回答1:
http://jsfiddle.net/odpw6c6q/43/
In ng-options
use ng-options="property.data.Bedrooms as
instead of ng-options="property.data.SubType as
because data.Bedrooms
is the property that contains number of bedrooms which should be stored in ng-model
In scope add this function
//Filter Function
$scope.greaterThan = function(bedrooms) {
return function(item) {
if ( item['Bedrooms'] > bedrooms) {
return true;
} else {
return false;
}
}
};
In ng-repeat
use filter: greaterThan(Bedrooms)
instead of filter:{Bedrooms:Bedrooms}
来源:https://stackoverflow.com/questions/29208242/angular-ng-repeat-filter-with-greater-than