Update index.html
Browse files- index.html +15 -6
index.html
CHANGED
|
@@ -35,18 +35,27 @@
|
|
| 35 |
</div>
|
| 36 |
|
| 37 |
<script>
|
| 38 |
-
let
|
| 39 |
|
| 40 |
async function fetchData() {
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
}
|
| 45 |
|
| 46 |
function populateDropdown() {
|
| 47 |
const selector = document.getElementById('jsonSelector');
|
| 48 |
|
| 49 |
-
|
| 50 |
const option = document.createElement('option');
|
| 51 |
option.value = index;
|
| 52 |
option.text = `Object ${index + 1}`;
|
|
@@ -60,7 +69,7 @@
|
|
| 60 |
const selectedIndex = selector.value;
|
| 61 |
|
| 62 |
if (selectedIndex >= 0) {
|
| 63 |
-
const jsonObject =
|
| 64 |
|
| 65 |
// Update the display container
|
| 66 |
displayContainer.innerHTML = `<div class="json-container">${renderJson(jsonObject)}</div>`;
|
|
|
|
| 35 |
</div>
|
| 36 |
|
| 37 |
<script>
|
| 38 |
+
let jsonDataArray = [];
|
| 39 |
|
| 40 |
async function fetchData() {
|
| 41 |
+
try {
|
| 42 |
+
const response = await fetch('characters.json'); // Corrected file name
|
| 43 |
+
if (!response.ok) {
|
| 44 |
+
throw new Error(`Failed to fetch data. Status: ${response.status}`);
|
| 45 |
+
}
|
| 46 |
+
const rawData = await response.text();
|
| 47 |
+
const lines = rawData.split('\n').filter(Boolean);
|
| 48 |
+
|
| 49 |
+
jsonDataArray = lines.map(line => JSON.parse(line));
|
| 50 |
+
} catch (error) {
|
| 51 |
+
console.error('Fetch error:', error.message);
|
| 52 |
+
}
|
| 53 |
}
|
| 54 |
|
| 55 |
function populateDropdown() {
|
| 56 |
const selector = document.getElementById('jsonSelector');
|
| 57 |
|
| 58 |
+
jsonDataArray.forEach((_, index) => {
|
| 59 |
const option = document.createElement('option');
|
| 60 |
option.value = index;
|
| 61 |
option.text = `Object ${index + 1}`;
|
|
|
|
| 69 |
const selectedIndex = selector.value;
|
| 70 |
|
| 71 |
if (selectedIndex >= 0) {
|
| 72 |
+
const jsonObject = jsonDataArray[selectedIndex];
|
| 73 |
|
| 74 |
// Update the display container
|
| 75 |
displayContainer.innerHTML = `<div class="json-container">${renderJson(jsonObject)}</div>`;
|