0

常にトリムを使用する代わりに、以下のコードの共通として一度だけ使用したい... plsは私を助けてくれます

if ("Company Profile" == $.trim(selectedValue)) {
    actionClass = "locationImportCompany.do?";
} else if ("Oppty Locations" == $.trim(selectedValue)) {
    actionClass = "locationImport.do?";
} else if ("Different Oppty" == $.trim(selectedValue)) {
    actionClass = "locationImportDiffOppty.do?";
} else if ("Loop TrackId Profile" == $.trim(selectedValue)) {
    actionClass = "locationImportLoopTrkId.do?";
} else if ("Inventory" == $.trim(selectedValue)) {
    isOrdering = "Y";
    actionClass = "inventoryLaunch.do?";
} else if ("Data Center List" == $.trim(selectedValue)) {
    actionClass = "locationImportDataCenter.do?";
} else if ("Customer AccountId" == $.trim(selectedValue)) {
    actionClass = "inventoryLaunch.do?";
} else if ("Customer Name" == $.trim(selectedValue)) {
    actionClass = "locationImportDataCenter.do?";
}
4

4 に答える 4

3

変数に格納します。

 var selectedValue = $.trim(selectedValue);

次に、次のようにします。

if (selectedValue == "Oppty Locations") {

}

等...

于 2013-03-13T09:52:31.430 に答える
2
var selectedValue = $.trim(selectedValue);
if ("Company Profile" == selectedValue) {
    actionClass = "locationImportCompany.do?";
} else if ("Oppty Locations" == selectedValue) {
    actionClass = "locationImport.do?";
} else if ("Different Oppty" == selectedValue) {
    actionClass = "locationImportDiffOppty.do?";
} else if ("Loop TrackId Profile" == selectedValue) {
    actionClass = "locationImportLoopTrkId.do?";
} else if ("Inventory" == selectedValue) {
    isOrdering = "Y";
    actionClass = "inventoryLaunch.do?";
} else if ("Data Center List" == selectedValue) {
    actionClass = "locationImportDataCenter.do?";
} else if ("Customer AccountId" == selectedValue) {
    actionClass = "inventoryLaunch.do?";
} else if ("Customer Name" == selectedValue) {
    actionClass = "locationImportDataCenter.do?";
}
于 2013-03-13T09:53:39.937 に答える
1

selectedValue をトリミングされた値で上書きして後で使用するか、変数に割り当てて使用します。

selectedValueTrimmed = $.trim(selectedValue)
if("Company Profile"==selectedValueTrimmed ){
于 2013-03-13T09:52:26.247 に答える
0

Else If文の代わりにSwitch文にする。

switch ($.trim(selectedValue)) {
    case: "Company Profile" 
        actionClass = "locationImportCompany.do?";
        break;
    case: "Oppty Locations" 
        actionClass = "locationImport.do?";
        break;
   // So on ...
} 
于 2013-03-13T10:12:51.647 に答える