Skip to content

Commit 2126324

Browse files
authored
Merge pull request #260 from ChristianBDev/main
New API fetch while sorting data from A-Z upper and lower by name
2 parents f2fb43e + 4802250 commit 2126324

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

html/index.html

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,14 @@
273273
},
274274
methods: {
275275
async fetchData() {
276-
const response = await fetch('https://countriesnow.space/api/v0.1/countries/');
277-
if(response){
276+
const response = await fetch("https://api.sampleapis.com/countries/countries");
277+
278+
if (response.ok) {
278279
const data = await response.json();
279-
const result = data.data;
280+
const countryNames = data.map((country) => country.name);
281+
const result = countryNames.sort((a, b) => a.localeCompare(b));
280282

281-
const selectDrop = document.getElementById('nationality');
282-
283-
result.forEach(obj => {
284-
viewmodel.nationalities.push(obj.country);
285-
});
283+
this.nationalities = result;
286284
}
287285
},
288286
click_character: function(idx, type) {
@@ -454,4 +452,4 @@
454452

455453
});
456454
</script>
457-
</html>
455+
</html>

0 commit comments

Comments
 (0)