每个HTML表格行仅循环一次

时间:2019-12-09 06:30:30

标签: jquery html

我想在表行上实现编辑功能。因此,在加载页面时,我获取用户选择的值,并为其余的下拉值获取JSON。如果用户选择的值等于任何JSON值,则将其跳过。问题是我的javascript循环了很多HTML行。如何确保只获取一次JSON并仍然跳过用户在每一行上选择的值?

这是我用来获取Json值并将其填充到下拉菜单中的代码

var selectedAccount = $("#mytable tbody tr .type_selected"); //The Drop Down Element
selectedAccount.each(function() {                      
    valueselected = $(this).val();//Value User had Selected
    $.getJSON(url, function (data,e) {//Get Json
        $.each(data, function (key, entry) {
            if(entry.id == valueselected){
                return true; //Ski the Value No need of Diplaying It
            }
            dropdown.append($('<option id="itemId'+ entry.id+'"></option>').attr('value', entry.id).text(entry.name)); //append Here
                //alert(entry.No_);
            })                
        });
});

This is What I'm getting. It's Looping Twice Because I have Two Rows
 // dropdown.select2();

0 个答案:

没有答案