-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
86 lines (63 loc) · 2.79 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// How to read a JSON, iterate over it and print in the correct HTML location.
fetch('data.json').then(response => response.json()).then(data => {
///////// Goals
var goal_list = document.getElementsByClassName('goal');
var number_goals = goal_list.length;
for (let index = 0; index < number_goals; index++) {
goal_list[index].innerHTML = data.goals[index].goal;
}
///////// Skills
var skill_list = document.getElementsByClassName('skill_name');
var number_skills = skill_list.length;
var skill_body_list = document.getElementsByClassName('skill_body');
for (let index = 0; index < number_skills; index++) {
skill_list[index].innerHTML = data.skills[index].skill_name;
skill_body_list[index].innerHTML = data.skills[index].skill_body;
}
///////// Projects
var number_projects = data.projects.length;
var project_list = document.getElementsByClassName('project_name');
var project_body_list = document.getElementsByClassName('project_body');
var project_img_list = document.getElementsByClassName('project_img');
for (let index = 0; index < number_projects; index++) {
project_list[index].innerHTML = data.projects[index].project_name;
project_body_list[index].innerHTML = data.projects[index].project_body;
project_img_list[index].setAttribute('src', data.projects[index].project_img)
}
});
/*
At the moment, I can pull data from the JSON file and show it on the HTML.
I will figure out how to create a reusable HTML template to pass the
information over instead of building one by one.
*/
//===========================================================================
/*
#### Study this can help with the template.
#### This would go in the HTML
<template id="comment-template">
<li class="comment">
<div class="comment-author"></div>
<div class="comment-body"></div>
<div class="comment-actions">
<a href="#reply" class="reply">Reply</a>
</div>
</li>
</template>
#### This would be in the JS
// An array of comments.
var comments = [
{'author': 'Joe', 'body': 'I love this product.'},
{'author': 'Mary', 'body': 'Great idea. I have got to get me one of these!'},
{'author': 'Eric', 'body': 'These things are fantastic. I bought three.'}
];
// Get a reference to the comments list in the main DOM.
var commentsList = document.getElementById('comments');
// Loop through each of the comments and add them to the comments list.
for (var i = 0; i < comments.length; i++) {
var comment = comments[i];
var tmpl = document.getElementById('comment-template').content.cloneNode(true);
tmpl.querySelector('.comment-author').innerText = comment.author;
tmpl.querySelector('.comment-body').innerText = comment.body;
commentsList.appendChild(tmpl);
}
*/