Angular orderBy number sorting as text in ng-repeat

前端 未结 7 1457
天命终不由人
天命终不由人 2020-11-29 08:10

I have this data:

[{\"id\":\"42\",\"firstname\":\"Sarah\",\"lastname\":\"Dilby\",\"age\":\"40\",\"cars\":\"Yaris\"},
{\"firstname\":\"Jason\",\"lastname\":\"         


        
7条回答
  •  心在旅途
    2020-11-29 08:31

    You don't have to modify your JSON. You can pass a function to orderBy filter like this:

    $scope.sorterFunc = function(person){
        return parseInt(person.id);
    };
    
    
            {{person.id | number}}
            {{person.firstname}} 
            {{person.lastname}} 
            {{person.age | number}}
            {{person.cars}} 
     
    

提交回复
热议问题