$ scope.units给了我像这样的数据
[{“ name”:“ unit 12:Abc”,“ id”:“ K09A”},{“ name”:“ Unit 4:Xyz”,“ id”:“ C9J5”},{“ name”:“ Unit 1:Acx“,” id“:” X4C8“},{” name“:”单元4:Kxc“,” id“:” W230“},.....]
我使用过滤器调用ng-repeat中的名称
ng-repeat="unit in units | orderBy: 'name'"
但这给了我命令
单元1、10、11、12、2、3、4、5 ..
我想我需要解析什么。但是我无法解决问题。我可以进行哪些更改以整数顺序获取它。
您将需要function
为orderBy
过滤器创建一个吸气剂,如下所示:
控制器:
$scope.unitOrder = function(unit){ return parseInt(unit.name.split(' ')[1]);}
看法:
ng-repeat="unit in units|orderBy:unitOrder"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句