Se está desarrollando una ruleta, el código funciona correctamente con código codificado. El código se mostrará a continuación:
var totalSponsors = '${sponsors.size()}'; // Create new wheel object specifying the parameters at creation time. let theWheel = new Winwheel({ 'numSegments' : totalSponsors, // Specify number of segments. 'outerRadius' : 212, // Set outer radius so wheel fits inside the background. 'textFontSize' : 18, // Set font size as desired. 'segments' : // Define segments including colour and text. [ {'fillStyle' : '#eae56f', 'text' : 'Prize 1'}, {'fillStyle' : '#89f26e', 'text' : 'Prize 2'}, {'fillStyle' : '#7de6ef', 'text' : 'Prize 3'}, {'fillStyle' : '#e7706f', 'text' : 'Prize 4'}, {'fillStyle' : '#eae56f', 'text' : 'Prize 5'}, {'fillStyle' : '#89f26e', 'text' : 'Prize 6'}, {'fillStyle' : '#7de6ef', 'text' : 'Prize 7'}, {'fillStyle' : '#e7706f', 'text' : 'Prize 8'}, {'fillStyle' : '#eae56f', 'text' : 'Prize 9'}, {'fillStyle' : '#89f26e', 'text' : 'Prize 10'}, {'fillStyle' : '#7de6ef', 'text' : 'Prize 11'}, {'fillStyle' : '#e7706f', 'text' : 'Prize 12'}, {'fillStyle' : '#eae56f', 'text' : 'Prize 13'}, {'fillStyle' : '#89f26e', 'text' : 'Prize 14'}, {'fillStyle' : '#7de6ef', 'text' : 'Prize 15'}, {'fillStyle' : '#e7706f', 'text' : 'Prize 16'}, {'fillStyle' : '#eae56f', 'text' : 'Prize 17'}, {'fillStyle' : '#89f26e', 'text' : 'Prize 18'} ], 'animation' : // Specify the animation to use. { 'type' : 'spinToStop', 'duration' : 5, // Duration in seconds. 'spins' : totalSponsors, // Number of complete spins. 'callbackFinished' : alertPrize } }); // Insert the sponsor name in the roulette <c:forEach items='${sponsors}' var="index" varStatus="status"> //console.log("NAME: " + '${index.getSponsorName()}'); </c:forEach>Quiero insertar los datos de la lista de "patrocinadores" (bucle forEach) en el campo "texto" de la matriz "segmentos". Los nombres de cada patrocinador se obtienen con la siguiente línea de código:
'${index.getSponsorName()}'El código de la ruleta se ha obtenido del siguiente enlace:
Creo que su mejor opción sería crear la opción de "segmentos" como JSONArray en su controlador.
Random random = new Random(); int nextInt = random.nextInt(0xffffff + 1); JSONArray segments = new JSONArray(); for(Object item : sponsors){ segments.put(new JSONObject("{\"fillStyle\":\""+String.format("#%06x", nextInt)+"\",\"text\":\""+.getSponsorName()+"\"}")); } Entonces segments.toString le daría lo que necesita.
Consulte este enlace para obtener más información: https://www.baeldung.com/java-org-json