[英]Radio button selection creates a dynamic drop down list
我正在嘗試創建一個下拉列表,該列表根據在單選按鈕組中所做的選擇而動態填充。 我目前有一組單選按鈕,名稱為“適用性”,可供選擇的選項包括:人員,程序,環境,交付能力,技術適航性和運營適航性。 根據選擇的選項,我希望在下拉框中填充許多選項。 我目前正在使用的代碼是:
var peList = [“Worker Type”, “Injury Type”];
var enList = [“Undefined”];
var prList = ["Facility", "Building", "Plant", "Damage Type"];
var caList = ["To Be Determined"];
var teList = ["Aircraft", "Component"];
var opList = ["Nothing at the moment"];
if (Applicability.rawValue===”People”) {
DropDownList4.clearItems;
for (var i = 0; i < peList.length; i++) {
DropDownList4.addItem(peList[i]);
}
} else if (Applicability.rawValue===”Property”) {
DropDownList4.clearItems;
for (var i = 0; i < prList.length; i++) {
DropDownList4.addItem(prList[i]);
}
} else if (Applicability.rawValue===”Environment”) {
DropDownList4.clearItems;
for (var i = 0; i < enList.length; i++) {
DropDownList4.addItem(enList[i]);
}
} else if (Applicability.rawValue===”CapabilityToDeliver”) {
DropDownList4.clearItems;
for (var i = 0; i < caList.length; i++) {
DropDownList4.addItem(caList[i]);
}
} else if (Applicability.rawValue===”TechnicalAirworthiness”) {
DropDownList4.clearItems;
for (var i = 0; i < taList.length; i++) {
DropDownList4.addItem(taList[i]);
}
} else if (Applicability.rawValue===”OperationalAirworthiness”) {
DropDownList4.clearItems;
for (var i = 0; i < opList.length; i++) {
DropDownList4.addItem(opList[i]);}
您能幫我告訴我哪里可能出問題了嗎? 謝謝
clearitems是一種方法,應稱為DropDownList4.clearItems();。 請注意此處代碼中缺少的括號。 另外,通過使用switch使代碼更易於維護。 例如:
var a,al,ax; // array, array length, array index
switch(Applicability.rawValue){
case 'People': a=['Worker Type', 'Injury Type'];break;
case 'Property': a=['Facility', 'Building', 'Plant', 'Damage Type'];break;
case 'Environment': a=['Undefined'];break;
case 'CapabilityToDeliver': a=['To Be Determined'];break;
case 'TechnicalAirworthiness': a=['Aircraft', 'Component'];break;
case 'OperationalAirworthiness': a=['Nothing at the moment'];break;
default:
// put your exception handling code here.
}
DropDownList4.clearItems();
for(ax=0,al=a.length;ax<al;ax++){
DropDownList4.addItem(a[ax]);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.