Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
Insert data into a JSON array inside a Winwheel instance (Roulette) with javascript

A roulette is being developed, the code works correctly with hardcoded code. The code will be shown below:

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> 

I want to insert the data from the "sponsors" list (forEach loop) into the "text" field of the "segments" array. The names of each sponsor is obtained with the following line of code:

 '${index.getSponsorName()}'

The roulette code has been obtained from the following link:

http://dougtesting.net/winwheel/examples/basic_code_wheel

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I believe your best call would be creating the "segments" option as a JSONArray in your controller.

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()+"\"}"));
    }

Then segments.toString would give you what you need.

See this link for more: https://www.baeldung.com/java-org-json

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda