Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
task_33
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Гульняшкин Евгений
task_33
Commits
3233faf4
Commit
3233faf4
authored
1 year ago
by
Гульняшкин Евгений
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил комментарии для обьяснения работы промисов
parent
74f0a0ba
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
11 deletions
+10
-11
script.js
task_1/script.js
+10
-11
No files found.
task_1/script.js
View file @
3233faf4
...
@@ -36,28 +36,27 @@ const request = (config) => {
...
@@ -36,28 +36,27 @@ const request = (config) => {
})
})
}
}
const
processResultMainCountry
=
(
result
)
=>
{
const
processResultMainCountry
=
(
result
)
=>
{
// result - данные полученые от первого запроса хранят в себе страну и ее данные.
console
.
log
(
result
);
const
h2
=
document
.
createElement
(
'h2'
)
// создаем элемент чтобы добавить название основной страны в заголовок
const
h2
=
document
.
createElement
(
'h2'
)
h2
.
innerText
=
result
[
0
].
name
h2
.
innerText
=
result
[
0
].
name
const
ul
=
document
.
createElement
(
'ul'
)
const
ul
=
document
.
createElement
(
'ul'
)
// const items = createTree(result[0])
infoToshow
.
append
(
h2
)
infoToshow
.
append
(
h2
)
const
names
=
result
[
0
][
'borders'
].
map
(
item
=>
{
const
names
=
result
[
0
][
'borders'
].
map
(
item
=>
{
// здесь создаем и записываем все промисы которые позже запустим в Promise.all
return
request
({
method
:
'GET'
,
path
:
`https://restcountries.com/v3.1/alpha/
${
item
}
`
})});
return
request
({
method
:
'GET'
,
borderCountry
=
Promise
.
all
(
names
)
path
:
`https://restcountries.com/v3.1/alpha/
${
item
}
`
// каждый item - это код страны. Мы тут еще не вызываем запрос,
// только записываем в массив
})});
borderCountry
=
Promise
.
all
(
names
)
// здесь уже вызываем все запросы по границам, получаем опять массив
.
then
(
data
=>
{
.
then
(
data
=>
{
data
.
forEach
(
element
=>
{
data
.
forEach
(
element
=>
{
const
li
=
document
.
createElement
(
'li'
)
const
li
=
document
.
createElement
(
'li'
)
li
.
innerText
=
element
[
0
].
name
.
common
li
.
innerText
=
element
[
0
].
name
.
common
// получаем стандартное имя страны
ul
.
append
(
li
)
ul
.
append
(
li
)
});
});
})
})
infoToshow
.
append
(
ul
)
infoToshow
.
append
(
ul
)
console
.
log
(
borderCountry
);
loader
.
style
.
display
=
'none'
loader
.
style
.
display
=
'none'
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment