在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
答案 0 :(得分: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:通常变量以小写字母开头,类以大写字母开头
答案 1 :(得分:0)
if($.isArray( SelectList ) == false)
SelectList = SelectList.split(',');