Created
December 14, 2017 15:02
-
-
Save antecedent/fbd9ab441a91ba83f589872dce0ed534 to your computer and use it in GitHub Desktop.
Mini užduotis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="lt"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Pašto indeksai</title> | |
<script | |
src="https://code.jquery.com/jquery-3.2.1.js" | |
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" | |
crossorigin="anonymous"></script> | |
<style type="text/css"> | |
table { | |
border-collapse: collapse; | |
} | |
td { | |
padding: 10px; | |
border-bottom: 1px solid gray; | |
} | |
</style> | |
</head> | |
<body> | |
<table> | |
<tr> | |
<td>Saltoniškių g. 12</td> | |
<td> </td> | |
</tr> | |
<tr> | |
<td>Didlaukio g. 47</td> | |
<td> </td> | |
</tr> | |
<tr> | |
<td>Kalvarijų g. 98</td> | |
<td> </td> | |
</tr> | |
</table> | |
<script src="adresai.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
var sort = function() { | |
var result = $('tr').toArray().sort(function(a, b) { | |
a = $(a).find('td:last-child').text(); | |
b = $(b).find('td:last-child').text(); | |
if (a == b) { | |
return 0; | |
} | |
return a < b ? -1 : 1; | |
}); | |
$('table').empty().append($(result)); | |
}; | |
var makeHandler = function(cell) { | |
return function(data) { | |
cell.text(data.data[0].post_code); | |
sort(); | |
}; | |
}; | |
$('td:first-child').each(function() { | |
$.get({ | |
url: 'https://postit.lt/data/', | |
dataType: 'json', | |
data: { | |
address: $(this).text() + ', Vilnius' | |
} | |
}) | |
.done(makeHandler($(this).closest('tr').find('td:last-child'))) | |
.fail(function() { | |
window.alert('Negautas tinkamas atsakymas iš serviso.'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment