AngularJS orderByစစ်ထုတ် မှု


ဥပမာ

အရာများကို အက္ခရာစဉ်ဖြင့် ပြသပါ-

<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>

အဓိပ္ပါယ်နှင့် အသုံးပြုမှု

ဇ ကာ orderByသည် ကျွန်ုပ်တို့အား array တစ်ခုကို စီရန်ခွင့်ပြုသည်။

ပုံသေအားဖြင့်၊ စာကြောင်းများကို အက္ခရာစဉ်စီထားပြီး နံပါတ်များကို ဂဏန်းများဖြင့် စီထားသည်။


အထားအသို

{{ array | orderBy : expression : reverse }}

ကန့်သတ်တန်ဖိုးများ

Value Description
expression The expression used to determine the order. The expression can be of type:

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 examples below.

Function: You can create a function to organize the sorting.

Array: Use an array if you need more than one object property to determine the sorting order. The array items can be both strings and functions.
reverse Optional. Set to true if you want to reverse the order of the array.


နောက်ထပ် ဥပမာများ

ဥပမာ

ခင်းကျင်းခြင်းကို "မြို့" ဖြင့် စီပါ-

<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>

ဥပမာ

array ကို "မြို့" ဖြင့် ကြီးစဉ်ငယ်လိုက် စီပါ-

<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>

ဆက်စပ်စာမျက်နှာများ

AngularJS ကျူတိုရီရယ်- Angular Filters