Angular orderBy number sorting as text in ng-repeat

前端 未结 7 1468
天命终不由人
天命终不由人 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:47

    Let orderBy point to a method owned by the scope or its not isolated ancestors and let this method return a number casted from the string. You may have to write a directive inheriting the person scope created by the ngRepeat instances.. to add this method.

    Moreover in your case, the age is a string where it could have been an integer and so the numeric sort would be natively applied.

    If you cannot change the data serverside then alter it clientside while fetching.

提交回复
热议问题