进出口使用剑道和打字稿我的应用程序和我有点IP地址行无法弄清楚如何排序与字符串表示的IPv4地址如何在剑道UI电网
排序必须看起来像这样
1.1.1.1
10.1.1.1
50.1.1.1
100.1.1.1
100.2.1.1
255.255.255.255
行
内gridColumns我已经试过这样的事情:
{
field: "sourceIP",
title: this.$filter('translate')('tcMetadata.modules.widgets.tcConnectionsGrid.gridHeaders.sourceIP'),
type:"string",
sortable: {
compare: function(a,b){
var arr = [that.ipaddressregex(a.sourceIP), that.ipaddressregex(b.sourceIP)];
arr = arr.sort();
console.log(arr, "ARRRRRRRRRRRRRRRRRR");
return arr[0];
}
}
}
哪里that.ipaddressregex功能是:
public ipaddressregex(ip) {
ip = ip.split(".").map(function(i) {
return ("00"+i).slice(-3);
}).join(".");
ip = ip.replace(/\./g, "");
return ip;
}
功能只是增加了零的空场,并移除点 12.10.1.1
转化为012010001001
,然后javascript的sort()
方法会照顾
但我认为我的问题是什么,我return
在我的情况下return arr[0];
Ÿ已经修好了,我意识到它必须返回1或0或-1,但谢谢 –