Filtu orderBy AngularJS

Tafiyar da kuma amfani

orderBy Filtu yana bada la'akari don hanyar abin da yake da nau'i.

Dukansu na gaba daya, alama na hanyar yake ake hanyar abin da yake da alama, kuma abin da yake da nau'i ake hanyar nau'i.

Tarayya na yau

Tuturu AngularJS:Angular Filters

Shiyyar

Tosin 1

Ganiwa abin da yake nazarin:

<div ng-app="myApp" ng-controller="orderCtrl">
<ul>
<li ng-repeat="x in cars | orderBy">{{x}}</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('orderCtrl', function($scope) {
    $scope.cars = ["Dodge", "Fiat", "Audi", "Volvo", "BMW", "Ford"];
);
</script>

Try it yourself

Tosin 2

Boe "city" na hanyar tsa tsarin gudanarwa:
<div ng-app="myApp" ng-controller="orderCtrl">
<ul>
<li ng-repeat="x in customers | orderBy : 'city'">{{x.name + ", " + x.city}}</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('orderCtrl', function($scope) {
    $scope.customers = [
        {"name" : "Bottom-Dollar Marketse" ,"city" : "Tsawassen"},
        {"name" : "Alfreds Futterkiste", "city" : "Berlin"},
        {"name" : "Bon app", "city" : "Marseille"},
        {"name" : "Cactus Comidas para llevar", "city" : "Buenos Aires"},
        {"name" : "Bolido Comidas preparadas", "city" : "Madrid"},
        {"name" : "Around the Horn", "city" : "London"}
        {"name" : "B's Beverages", "city" : "London"}
    ];
);
</script>

Try it yourself

Tosin 3

Boe "city" na hanyar tsa tsarin gudanarwa:
<div ng-app="myApp" ng-controller="orderCtrl">
<ul>
<li ng-repeat="x in customers | orderBy : '-city'">{{x.name + ", " + x.city}}</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('orderCtrl', function($scope) {
    $scope.customers = [
        {"name" : "Bottom-Dollar Marketse" ,"city" : "Tsawassen"},
        {"name" : "Alfreds Futterkiste", "city" : "Berlin"},
        {"name" : "Bon app", "city" : "Marseille"},
        {"name" : "Cactus Comidas para llevar", "city" : "Buenos Aires"},
        {"name" : "Bolido Comidas preparadas", "city" : "Madrid"},
        {"name" : "Around the Horn", "city" : "London"}
        {"name" : "B's Beverages", "city" : "London"}
    ];
);
</script>

Try it yourself

Syntax

{{ array | orderBy : expression : reverse }}

Parameters

Parameters Description
expression

Expression used to determine the order. The expression can be of the following types:

String: If the array is an array of objects, you can sort the array by the value of one of the object properties. See the example above.

Function: You can create a function to organize sorting.

Array: If you need to determine the sorting order of multiple object properties, use an array. Array items can be strings and functions.

reverse Optional. If you want to reverse the order of the array, set it to true.