-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-09-2021.html
More file actions
153 lines (126 loc) · 4.56 KB
/
06-09-2021.html
File metadata and controls
153 lines (126 loc) · 4.56 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<table border="1">
<pranjal>
<tr>
<th>ID</th>
<th>User ID</th>
<th>Title</th>
<th>Body</th>
</tr>
</pranjal>
<tbody id="tableBody"></tbody>
<tbody id="bodyDetails"></tbody>
</table>
<script>
//API or Local Host.....
const fetchCall = fetch('https://jsonplaceholder.typicode.com/posts'); //unchangable ......... constet
console.log(fetchCall);
const responce = fetchCall.then((res) => res.json()).catch((err) => console.log(err));
responce.then((res) => {
console.log(res);
document.getElementById('tableBody').innerHTML = renderTableData(res);
})
//map ::
//.json and .JSON
const renderTableData = (list) => {
return list.map(
(item) =>
`<tr onclick="mainFn(${item.id-1})">
<td id="selectId">${item.id}</td>
<td>${item.userId}</td>
<td>${item.title}</td>
<td>${item.body}</td>
</tr>`
)
}
function mainFn(r) {
responce.then((respo) => {
document.getElementById("tableBody").style.display = "none";
document.getElementById("bodyDetails").innerHTML =
`<tr>
<td>${respo[r].id}</td>
<td>${respo[r].userId}</td>
<td>${respo[r].title}</td>
<td>${respo[r].body}</td>
</tr> </br> <button onclick="refresh()">Go Back</button>
<button onclick="window.print()">Print</button>`;
})
}
function refresh() {
location.reload();
}
</script>
<!-- <script>
// let store = {};
const fetchCall = fetch('https://jsonplaceholder.typicode.com/posts');
const response = fetchCall
.then((res) => res.json())
.catch((err) => console.error(err));
response.then((res) => {
console.log('res1 :: ', res);
// store = res;
// console.log("StoreInside:: ", store);
document.getElementById('tableBody').innerHTML = renderTableData(res);
globleData(res);
});
//console.log("StoreOutSide:: ", store);
// Decliare a variable [] => and push the API data here.
// let cloneData = JSON.parse(JSON.stringify(Object));
// deep clone....
function globleData(res) {
let cloneData = JSON.parse(JSON.stringify(res));
}
const renderTableData = (list) => {
return list?.map(
(item) => `<tr onclick="mainFn(${item.id})">
<td id="selectId">${item.id}</td>
<td>${item.userId}</td>
<td>${item.title}</td>
<td>${item.body}</td>
</tr>`
);
};
const renderTableDetails = (details) => {
return `<tr>
<td>${details[0]}</td>
<td>${details[1]}</td>
<td>${details[2]}</td>
<td>${details[3]}</td>
</tr> </br> <button onclick="refresh()">Go Back</button>`
};
function refresh() {
location.reload();
}
function mainFn(id) {
response.then((respo) => {
document.getElementById("tableBody").style.display = "none";
console.log(respo[id - 1])
const propName = Object.values(respo[id - 1])
document.getElementById("bodyDetails").innerHTML = renderTableDetails(propName);
});
// const resp = fetchCall
// .then((val) => val.json())
// .catch((error) => console.error(error));
// resp.then((val) => {
// console.log("val:: ", val)
// // document.getElementById("tableBody").style.display = "none";
// // document.getElementById("bodyDetails").innerHTML = renderTableDetails(val);
// });
}
// var clickData = document.querySelector("#selectId");
// function sendRes(res) {
// const strore = { ...res }
// return strore;
// }
// clickData.addEventListener("click", sendRes(item.id));
</script> -->
</body>
</html>