Angular Sorting with null objects

前端 未结 4 1186
耶瑟儿~
耶瑟儿~ 2020-12-21 05:39

I need to take records with null values on top , when I\'m sorting by ASC



        
4条回答
  •  心在旅途
    2020-12-21 06:13

    I know this is an old post but there is a better way for doing this and could not see it anywhere.

    var myApp = angular.module('myApp', []);
    
    myApp.controller('myCtrl', ["$scope", function($scope){
      $scope.footballers = [
            {id: 0, qt: 13},
            {id: 1, qt: 2},
            {id: 2, qt: 124},
            {id: 3, qt: 12125},
            {id: null , qt: 122},
            {id: 4, qt: -124},
            {id: 5, qt: -5235},
            {id: 6, qt: 43},
            ]
    }]) 
    
    
    
    
    
    {{footballer.id}}, {{footballer.qt}}

    One can also use this to show 'id' with any specific value on top of others

提交回复
热议问题