Skip to content

Commit d67ccdd

Browse files
authored
Merge pull request #10 from driftluo/modify_ip_js
Modify ip_list.js
2 parents 331fb55 + 4c97ea0 commit d67ccdd

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

static/js/admin/ip_list.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ $(function () {
44
});
55

66
function get_ip() {
7-
$.getJSON("/api/v1/ip/view?limit=10&offset=" + page.page * 10, function (result) {
7+
$.getJSON("/api/v1/ip/view?limit=25&offset=" + page.page * 25, function (result) {
88
if (result.data.length < 10) {
99
$("#next").attr({ "disabled": "disabled" });
1010
}
11-
11+
var ip_unique, ip_list = [];
1212
for(var i = 0; i < result.data.length; i++){
1313
var data = JSON.parse(result.data[i]);
1414
data.timestamp = moment.utc(data.timestamp).local().format();
1515
var html = template("tpl-ip", data);
1616
$("tbody").append(html);
17-
result.data[i] = data;
17+
ip_list.push(data.ip)
1818
}
1919

20-
for (var i = 0; i < result.data.length; i++) {
21-
$.getJSON("//www.freegeoip.net/json/" + result.data[i].ip, function (res) {
20+
ip_unique = ip_list.filter(function (element,index,self) { return self.indexOf(element) === index; });
21+
22+
for (var i = 0; i < ip_unique.length; i++) {
23+
$.getJSON("//www.freegeoip.net/json/" + ip_unique[i], function (res) {
2224
$(".region[data-ip='" + res.ip+ "']").text(res.region_name);
2325
$(".country[data-ip='" + res.ip+ "']").text(res.country_name);
2426
})

0 commit comments

Comments
 (0)