簡體   English   中英

jQuery inArray沒有返回正確的值

[英]Jquery inArray not returning correct value

在Firebug中,當我將SelectList變量翻轉時,它肯定看起來像一個數組。

if (GroupList != "") {
    $('select[name^=DDLColumns1] option').each(function(){
        if ($(this).val() != "-1") {
            var ItemsArray = $(this).val().split('|');
            var DataTypes = ItemsArray[1];
            var TestItem = "[" + ItemsArray[0] + "]";

PROBLEM IS HERE---> if (jQuery.inArray(TestItem, SelectList) != -1) {
                    if(DataTypes == 104)
                        NewSelectList += " SUM(CAST(" + ItemsArray[0] + " AS INT)) as " + ItemsArray[0] + ",";
                else
                    NewSelectList += " max(" + ItemsArray[0] + ") as " + ItemsArray[0] + ",";
            }

        }
    });
if(NewSelectList.length > 0) {
        NewSelectList = NewSelectList.substring(0, NewSelectList.length - 1);
        SelectList = NewSelectList;
    }

}//end of if GroupList is not empty

首先清理那一團糟怎么辦? 如果這樣做,您的錯誤應該會清楚。

if (GroupList != "") {
    $('select[name^=DDLColumns1] option').each(function() {
        if ($(this).val() != "-1") {
            var ItemsArray = $(this).val().split('|');
            var DataTypes = ItemsArray[1];
            var TestItem = "[" + ItemsArray[0] + "]";

            if (jQuery.inArray(TestItem, SelectList) != -1) {
                if(DataTypes == 104)
                    NewSelectList += " SUM(CAST(" + ItemsArray[0] + " AS INT)) as " + ItemsArray[0] + ",";

                else // <--- why all of a sudden no {}?

                    NewSelectList += " max(" + ItemsArray[0] + ") as " + ItemsArray[0] + ",";
            }
            //} //<--- why is commented out? it breaks everything

        } //<-- this closes the callback

}); //<-- broken close of the if

if(NewSelectList.length > 0) {
    NewSelectList = NewSelectList.substring(0, NewSelectList.length - 1);
    SelectList = NewSelectList;
}



} // <---- what is this for? yeah it's broken

PS:通常,變量以小寫字母開頭,而類以大寫字母開頭

   if($.isArray( SelectList ) == false)
    SelectList = SelectList.split(',');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM