KikiQiQi commited on
Commit
7094cc7
1 Parent(s): 466c373

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +79 -17
index.html CHANGED
@@ -1,19 +1,81 @@
1
  <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
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">
6
+ <title>JSON Viewer with Selector</title>
7
+ <style>
8
+ body {
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
+ <label for="jsonSelector">选择展示数据:</label>
26
+ <select id="jsonSelector" onchange="updateDisplay()">
27
+ {% for index in range(json_objects|length) %}
28
+ <option value="{{ index }}">Object {{ index + 1 }}</option>
29
+ {% endfor %}
30
+ </select>
31
+ </form>
32
+
33
+ <div id="jsonDisplayContainer">
34
+ <!-- JSON data will be displayed here -->
35
+ </div>
36
+
37
+ <script>
38
+ const jsonObjects = JSON.parse('{{ json_objects | tojson | safe }}');
39
+
40
+ function updateDisplay() {
41
+ const selector = document.getElementById('jsonSelector');
42
+ const displayContainer = document.getElementById('jsonDisplayContainer');
43
+ const selectedIndex = selector.value;
44
+
45
+ if (selectedIndex >= 0) {
46
+ const jsonObject = jsonObjects[selectedIndex];
47
+
48
+ // Update the display container
49
+ displayContainer.innerHTML = `<div class="json-container">${renderJson(jsonObject)}</div>`;
50
+ } else {
51
+ displayContainer.innerHTML = ''; // Clear the display if no option is selected
52
+ }
53
+ }
54
+
55
+ function renderJson(obj) {
56
+ const orderedKeys = ['name', 'age', 'gender', "race", "education", "occupation", "expertise", "hobby", "positive_personality", "negative_personality"]; // 按照指定顺序排列的键
57
+ let html = '';
58
+
59
+ // 遍历指定顺序的键,将其对应的键值对添加到 HTML 中
60
+ orderedKeys.forEach(key => {
61
+ if (key in obj) {
62
+ html += `<div><span class="json-key">${key}:</span> ${obj[key]}</div>`;
63
+ }
64
+ });
65
+
66
+ // 遍历其他未在指定顺序中的键,将其对应的键值对添加到 HTML 中
67
+ for (const [key, value] of Object.entries(obj)) {
68
+ if (!orderedKeys.includes(key)) {
69
+ html += `<div><span class="json-key">${key}:</span> ${value}</div>`;
70
+ }
71
+ }
72
+
73
+ return html;
74
+ }
75
+
76
+ // Initial update to display the first JSON object
77
+ updateDisplay();
78
+ </script>
79
+
80
+ </body>
81
  </html>