|
51 | 51 | </div> |
52 | 52 | <div id="results"> |
53 | 53 | {{ range $i, $val := .Results }} |
54 | | - {{ if eq $.VoteType "ranked" }} |
55 | | - <h4 class="mb-3"><u>Round {{ $i | inc }}</u></h4> |
56 | | - {{ end }} |
57 | | - {{ range $option, $count := $val }} |
58 | | - <div id="{{ $option }}" class="fs-5 lh-sm"> |
59 | | - {{ $option }}: {{ $count }} |
| 54 | + <div id="round-{{ $i }}"> |
| 55 | + {{ if eq $.VoteType "ranked" }} |
| 56 | + <h4 class="mb-3"><u>Round {{ $i | inc }}</u></h4> |
| 57 | + {{ end }} |
| 58 | + {{ range $option, $count := $val }} |
| 59 | + <div id="{{ $i }}-{{ $option }}" class="fs-5 lh-sm"> |
| 60 | + {{ $option }}: {{ $count }} |
| 61 | + </div> |
| 62 | + {{ end }} |
60 | 63 | </div> |
61 | 64 | <br /> |
62 | | - {{ end }} |
63 | 65 | {{ end }} |
64 | 66 | </div> |
65 | 67 | {{ if and (.CanModify) (not .IsHidden) }} |
|
82 | 84 |
|
83 | 85 | eventSource.addEventListener("{{ .Id }}", function (event) { |
84 | 86 | let data = JSON.parse(event.data); |
85 | | - if (data.length == 0) return; |
86 | | - let results = data[0]; |
87 | | - for (let option in results) { |
88 | | - let count = results[option]; |
89 | | - let element = document.getElementById(option); |
90 | | - if (element == null) { |
91 | | - let newElement = document.createElement("div"); |
92 | | - newElement.id = option; |
93 | | - newElement.style = "font-size: 1.25rem; line-height: 1.25"; |
94 | | - newElement.innerText = option + ": " + count; |
95 | | - document.getElementById("results").appendChild(newElement); |
| 87 | + for (let roundNum in data) { |
| 88 | + for (let option in data[roundNum]) { |
| 89 | + let count = data[roundNum][option]; |
| 90 | + let element = document.getElementById(`${roundNum}-${option}`); |
| 91 | + if (element == null) { |
| 92 | + let newElement = document.createElement("div"); |
| 93 | + newElement.id = option; |
| 94 | + newElement.style = "font-size: 1.25rem; line-height: 1.25"; |
| 95 | + newElement.innerText = option + ": " + count; |
| 96 | + console.log(`round-${roundNum}`); |
| 97 | + document.getElementById(`round-${roundNum}`).appendChild(newElement); |
| 98 | + } |
| 99 | + element.innerText = option + ": " + count; |
96 | 100 | } |
97 | | - element.innerText = option + ": " + count; |
98 | 101 | } |
99 | 102 | }); |
100 | 103 | </script> |
|
0 commit comments