Javascript Jquery未返回正确的值

Javascript Jquery未返回正确的值,javascript,jquery,Javascript,Jquery,在Firebug中,当我滚动SelectList变量时,它看起来确实像一个数组 if (GroupList != "") { $('select[name^=DDLColumns1] option').each(function(){ if ($(this).val() != "-1") { var ItemsArray = $(this).val().split('|'); var DataTypes = ItemsArr

在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:通常情况下,变量以小写字母开头,类以大写字母开头

如果jQuery.inArrayItemsArray[0],SelectList!=-1{你的代码乱七八糟…要把它清理干净…有人会回答实际问题吗???这不是我的错,这个论坛上的缩进和我的缩进不一样,这让它看起来乱七八糟。选择列表包含[DateDue],[TypeFileID],等等。所以我需要格式化TestItem变量以匹配SelectList中的值。请再次查看,我看到了5{和5}'s@Lyle这并没有什么好处,关闭}的顺序仍然被打破。为什么不呢{s?因为if和else语句只执行一条语句。@Lyle除非你给我们看一些实际的工作代码,否则我们只能猜测你的代码是什么样子,要不要编辑你的答案?@Lyle…goosh..但现在对我们来说…我们只能猜测。ItemsArray的内容是什么?你想用同样的方式格式化它以使其匹配,所以我需要知道里面的东西看起来怎么样。
   if($.isArray( SelectList ) == false)
    SelectList = SelectList.split(',');