简体   繁体   中英

JQuery Select Options Not Updating \

So I'm trying to update a list of options using the select options in html which is shown as:

   <select id="weight" data-global="true" class="weight-select"></select>

That is a selection of just weight classes.

Then I am trying to populate that current selection option with values, text and numbers from a user input elsewhere (don't worry about that since its working). In my JS this is what I have to populate it.

var options = [match.players.length];

    $.each(options, 
        function(index){
    //player = match.players[index]
    options.push('<option>' + match.players.length + '</option>');

    });

    $('#weight').html(options.join(''));

Now I'm just testing out whether it is updating or not with this code so ignore the commeted out lines. So match.players.length is just the length of a matchContainer of players. This code input a value of 0 in the selection drop down, BUT when I populate match.players with more then 1 player it does not update, and yes I am running the function where this code when updating my match.players

So overall, I'm currently just trying to get my select options to populate as long as a user inputs values of match.players[0], match.players[1] etc... (Behind the scenes it works so just assume it's updating) to update my selection based on how many user inputs there are so just the length. With the drop down selection pane having the values of 0,1,2,3,4,5... based on how many user inputs. So far it's just stuck at 0 the current array length when there is no user input.

var options = [match.players.length];

This is just going to make an array of length 1 with the value being the length of match.players , which I'm pretty sure is not what you want to do.

Just set options to equal match.players and iterate over that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM