【发布时间】:2018-07-19 15:10:18
【问题描述】:
我有一个表头 IP 地址,它使用 AngularJS 对其进行排序。 不幸的是,它似乎没有对 IP 地址进行排序。
<th class="text-left">
<a href="" ng-click="sortType = 'device.ip_address'; sortReverse = !sortReverse">
IP Address
</a>
</th>
我想用这样的东西
sortFn: function (a, b) {
if (a == b) return 0;
if ( +a.replace(/\./g, '') < +b.replace(/\./g, '')) return - 1;
return 1;
}
如何在 AngularJS 中使用上面的这个函数作为我的排序函数?
【问题讨论】:
-
你能解释一下你所拥有的有什么问题吗?
-
它似乎没有排序。因为它把它当作一个字符串。
-
创建自定义过滤器:
.filter('myFilter', function() { return function(ips, reverse) { var temp = ips.sort(sortFn); return reverse ? temp.reverse() : temp; }}).
标签: angularjs sorting filter html-table ng-filter