Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

90
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda