[英]How do I sort a list alphabetically and numerically in angularjs?
Here is my scenario 这是我的情况
<selectclass="form-control" id="my_select"><optionvalue="0">List is Number</option><option value="1">List is Alphabetical</option></select> <liclass="ui-state-default " ng-repeat="damageResult in damageResultList> <span>{{damageResult.damageMechanismList}}hfgh</span></li>
what you can do is define a custom function to sort and convert the text to number in case field is number 您可以做的是定义一个自定义函数,以在字段为数字的情况下对文本进行排序并将其转换为数字
$scope.sorterFunc = function(entity){
return $scope.isFieldNumber? parseInt(entity[$scope.property], 10) : entity[$scope.property];
};
and then in ng-repeat 然后在ng-repeat中
<div ng-repeat="entity in entityArray | orderBy:sorterFunc ">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.