Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!