2010-11-23 112 views
-1

在Firebug中,当我滚动SelectList变量时,它肯定看起来像一个数组。Jquery inArray不返回正确的值

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 
+0

在黑暗中只是一个尝试,如果(jQuery.inArray(ItemsArray [0]的SelectList)! = -1){ – Gazler 2010-11-23 19:40:13

+0

你的代码是一团糟...要去清理它... – 2010-11-23 19:41:31

回答

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

那么首先清理那个混乱怎么样?你的错误应该清楚,如果你这样做。

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:常变量以小写字母和类以大写一个