简体   繁体   English

jQuery选择选项不更新\\

[英]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: 所以我试图使用html中的选择选项更新选项列表,显示为:

   <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. 在我的JS中,这就是我要填充的内容。

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. 因此match.players.length只是玩家的matchContainer的长度。 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 这段代码在选择下拉列表中输入了0值,但是当我填充match.players并包含1个以上的球员时,它不会更新,是的,我正在运行该函数来更新我的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. 所以总的来说,只要用户输入match.players [0],match.players [1]等值,我目前就想尝试填充我的选择选项(在幕后它可以正常工作,所以假设(正在更新),以根据用户输入的数量(长度)来更新我的选择。 With the drop down selection pane having the values of 0,1,2,3,4,5... based on how many user inputs. 根据用户输入的数量,下拉选择窗格的值为0、1、2、3、4、5...。 So far it's just stuck at 0 the current array length when there is no user input. 到目前为止,在没有用户输入的情况下,它仅停留在当前数组长度的0处。

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. 这只是要创建一个长度为1的数组,值是match.players的长度,我敢肯定这不是您想要的。

Just set options to equal match.players and iterate over that. 只需将选项设置为相等match.players并对其进行迭代即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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