Update index.html
Browse files- index.html +48 -44
index.html
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="en">
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
@@ -9,36 +10,35 @@
|
|
9 |
font-family: Arial, sans-serif;
|
10 |
margin: 20px;
|
11 |
}
|
|
|
12 |
.json-container {
|
13 |
border: 1px solid #ccc;
|
14 |
padding: 10px;
|
15 |
margin-bottom: 10px;
|
16 |
}
|
|
|
17 |
.json-key {
|
18 |
font-weight: bold;
|
19 |
}
|
20 |
</style>
|
21 |
</head>
|
|
|
22 |
<body>
|
23 |
|
24 |
-
<form id="jsonSelectorForm">
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
<option value="{{ index }}">Object {{ index + 1 }}</option>
|
29 |
-
{% endfor %}
|
30 |
-
</select>
|
31 |
-
</form>
|
32 |
|
33 |
-
<div id="jsonDisplayContainer">
|
34 |
-
|
35 |
-
</div>
|
36 |
|
37 |
-
<script>
|
38 |
-
|
39 |
|
40 |
async function fetchData() {
|
41 |
-
const response = await fetch('
|
42 |
const data = await response.text();
|
43 |
jsonObjects = data.split('\n').filter(Boolean).map(JSON.parse);
|
44 |
}
|
@@ -54,46 +54,50 @@
|
|
54 |
});
|
55 |
}
|
56 |
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
const displayContainer = document.getElementById('jsonDisplayContainer');
|
61 |
-
const selectedIndex = selector.value;
|
62 |
-
|
63 |
-
if (selectedIndex >= 0) {
|
64 |
-
const jsonObject = jsonObjects[selectedIndex];
|
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 |
-
</script>
|
97 |
|
98 |
</body>
|
|
|
99 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
+
|
4 |
<head>
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
10 |
font-family: Arial, sans-serif;
|
11 |
margin: 20px;
|
12 |
}
|
13 |
+
|
14 |
.json-container {
|
15 |
border: 1px solid #ccc;
|
16 |
padding: 10px;
|
17 |
margin-bottom: 10px;
|
18 |
}
|
19 |
+
|
20 |
.json-key {
|
21 |
font-weight: bold;
|
22 |
}
|
23 |
</style>
|
24 |
</head>
|
25 |
+
|
26 |
<body>
|
27 |
|
28 |
+
<form id="jsonSelectorForm">
|
29 |
+
<label for="jsonSelector">Choose Data to Display:</label>
|
30 |
+
<select id="jsonSelector" onchange="updateDisplay()"></select>
|
31 |
+
</form>
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
<div id="jsonDisplayContainer">
|
34 |
+
<!-- JSON data will be displayed here -->
|
35 |
+
</div>
|
36 |
|
37 |
+
<script>
|
38 |
+
let jsonObjects;
|
39 |
|
40 |
async function fetchData() {
|
41 |
+
const response = await fetch('your_data_file.txt'); // Replace 'your_data_file.txt' with the actual file path
|
42 |
const data = await response.text();
|
43 |
jsonObjects = data.split('\n').filter(Boolean).map(JSON.parse);
|
44 |
}
|
|
|
54 |
});
|
55 |
}
|
56 |
|
57 |
+
function updateDisplay() {
|
58 |
+
const selector = document.getElementById('jsonSelector');
|
59 |
+
const displayContainer = document.getElementById('jsonDisplayContainer');
|
60 |
+
const selectedIndex = selector.value;
|
61 |
|
62 |
+
if (selectedIndex >= 0) {
|
63 |
+
const jsonObject = jsonObjects[selectedIndex];
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
// Update the display container
|
66 |
+
displayContainer.innerHTML = `<div class="json-container">${renderJson(jsonObject)}</div>`;
|
67 |
+
} else {
|
68 |
+
displayContainer.innerHTML = ''; // Clear the display if no option is selected
|
69 |
+
}
|
70 |
}
|
|
|
71 |
|
72 |
+
function renderJson(obj) {
|
73 |
+
const orderedKeys = ['name', 'age', 'gender', "race", "education", "occupation", "expertise", "hobby", "positive_personality", "negative_personality"];
|
74 |
+
let html = '';
|
75 |
|
76 |
+
orderedKeys.forEach(key => {
|
77 |
+
if (key in obj) {
|
78 |
+
html += `<div><span class="json-key">${key}:</span> ${obj[key]}</div>`;
|
79 |
+
}
|
80 |
+
});
|
|
|
81 |
|
82 |
+
for (const [key, value] of Object.entries(obj)) {
|
83 |
+
if (!orderedKeys.includes(key)) {
|
84 |
+
html += `<div><span class="json-key">${key}:</span> ${value}</div>`;
|
85 |
+
}
|
86 |
}
|
87 |
+
|
88 |
+
return html;
|
89 |
}
|
90 |
|
91 |
+
// Initialize the page
|
92 |
+
async function initializePage() {
|
93 |
+
await fetchData();
|
94 |
+
populateDropdown();
|
95 |
+
updateDisplay();
|
96 |
+
}
|
97 |
|
98 |
+
initializePage();
|
99 |
+
</script>
|
|
|
100 |
|
101 |
</body>
|
102 |
+
|
103 |
</html>
|