我在 if 语句中动态创建条件并将其存储在 Profile_Filter 变量中,但是当我对数组运行它时,它会将所有记录添加到我的临时数组中,而不是添加匹配的记录。
var Profile_Filter = "";
if ($("#DoctorNameDropDown option:selected").text() != "- Select One -") {
Profile_Filter += 'gAssessorsCompanyAssociationsArray[i].Name == $("#DoctorNameDropDown option:selected").val()';
}
if ($("#Degree").val() != "") {
var Degree_Filter = "";
var Degree = $("#Degree").val().split(";");
for (var i = 0; i < Degree.length; i++) {
if (Degree[i] == "") {
Degree.splice(i, 1);
i--;
}
}
if (Degree.length > 1) {
for (var j = 0; j < Degree.length; j++) {
if (j == 0) {
Degree_Filter += '(gAssessorsCompanyAssociationsArray[i].Degree.indexOf("' + Degree[j] + '") > 0';
} else {
Degree_Filter += ' && gAssessorsCompanyAssociationsArray[i].indexOf("' + Degree[j] + '") > 0';
}
}
Degree_Filter += ")";
} else Degree_Filter += '(gAssessorsCompanyAssociationsArray[i].Degree.indexOf("' + Degree[0] + '") > 0';
if (Profile_Filter != "") Profile_Filter += " && " + Degree_Filter; else Profile_Filter += Degree_Filter;
}
var temp = [];
for (var i = 0; i < gAssessorsCompanyAssociationsArray.length; i++) {
if (Profile_Filter) alert(gAssessorsCompanyAssociationsArray[i].Name);
}