2016-11-03 1 views
-1

Im folgenden Skript habe ich zwei Callback-Funktionen: getProjectKey() und getWorkflowSchemeName().Switch-Anweisung in JavaScript funktioniert nicht

Ich habe die Variable 'workflowSchemeName' in der switch-Anweisung übergeben, obwohl ich im Debugger sehen kann, dass der Wert kommt, aber die switch-Anweisung nicht funktioniert und auf dem Standardfall weiterläuft.

Folgendes ist der Code.

if (AJS.$("#issue-create-submit").val() == "Create" || AJS.$("#create-issue-submit").val() == "Create") { 
 
    inputTag = AJS.$("#project")[0]; 
 
    projectId = inputTag.value; 
 

 
    var projectKey; 
 
    var workflowSchemeName; 
 

 
    function getProjectKey(projectId, callback) { 
 
    console.log("Project ID is (inside function): " + projectId); 
 
    var restCall = AJS.params.baseURL + "/rest/api/2/project/" + projectId; 
 

 
    AJS.$.get(restCall, function(response) { 
 
     callback(response); 
 
     console.log(" REST PROJECT KEY IS : " + response.key); 
 
    }) 
 
    } 
 

 
    function getWorkflowSchemeName(projectKey, callback) { 
 
    var restCall = AJS.params.baseURL + "/rest/projectconfig/1/workflowscheme/" + projectKey; 
 

 
    AJS.$.get(restCall, function(response) { 
 
     callback(response); 
 
     console.log(" REST WorkflowScheme Name is: " + response.name); 
 
    }) 
 
    } 
 

 
    if (projectId != null) { 
 
    getProjectKey(projectId, function(response) { 
 
     projectKey = response.key; 
 
     console.log("*************** PROJECT KEY IS : " + projectKey); 
 

 
     if (projectKey != null) { 
 
     getWorkflowSchemeName(projectKey, function(resp) { 
 
      workflowSchemeName = resp.name; 
 

 
      // Getting the WorkflowSchemeName till here. CAN see it in the console. 
 

 
      console.log("*************** WORKFLOWSCHEME IS : " + workflowSchemeName); // Can see this. 
 

 
      if (workflowSchemeName != null) { 
 
      switch (workflowSchemeName) { 
 

 
       // FAILING HERE 
 
       case "SW Work Flow Scheme": 
 
       console.log("SOFTWARE New Content Inside condition "); 
 
       AJS.$(".field-group").children('label[for=description]').append('<span class="aui-icon icon-required"></span>'); 
 
       AJS.$(".field-group").children('label[for=customfield_10105]').append('<span class="aui-icon icon-required"></span>'); 
 
       break; 
 

 
       case "HW Workflow Scheme": 
 
       console.log("HARDWARE New Content Inside condition "); 
 
       AJS.$(".field-group").children('label[for=description]').append('<span class="aui-icon icon-required"></span>'); 
 
       break; 
 

 

 
       // DEFAULT CASE ALWAYS RUNS. 
 

 
       default: 
 
       console.log("A new workflow scheme is detected. Need to update the Scripts Plugin in Create Issue Screens"); 
 
      } 
 
      } 
 
     }) 
 
     } 
 
    }) 
 
    } 
 

 
    // Can't see these values here either. But separate Issue. 
 
    console.log("Project Key is ************** " + projectKey); 
 
    console.log("WorkflowScheme Name is ******** " + workflowSchemeName); 
 
}

Kann mir jemand bitte helfen Sie, was mache ich hier falsch? Vielen Dank.

+0

Warum nicht Sie uns das Protokoll des Wertes zeigen, von Ihrem REST-Service zu kommen? Es ist sehr schwierig zu sagen, was falsch ist, wenn Sie Ihre Eingaben nicht anzeigen. Vielleicht möchten Sie diese Log-Anweisungen setzen, bevor Sie Callback anrufen – Tibrogargan

+0

@ Prasad, warum wäre das wichtig? – Tibrogargan

+0

Ihr workflowSchemeName kann zusätzlichen Speicherplatz enthalten. Bitte schau es dir an. Es ist nichts falsch in Ihrem Switch-Fall. – Prasath

Antwort

1

Die switch-Anweisung ist korrekt. Das Problem ist der Wert von var workflowSchemaName ist nicht das, was Sie im switch case suchen (Leerzeichen und Groß-/Kleinschreibung). Überprüfen Sie dies.

var workflowSchemeName = 'SW Work Flow Scheme'; 

    switch (workflowSchemeName) { 

     // FAILING HERE 
    case "SW Work Flow Scheme": 
     console.log("SOFTWARE New Content Inside condition "); 
     //AJS.$(".field-group").children('label[for=description]').append('<span class="aui-icon icon-required"></span>'); 
     //AJS.$(".field-group").children('label[for=customfield_10105]').append('<span class="aui-icon icon-required"></span>'); 
     break; 

    case "HW Workflow Scheme": 
     console.log("HARDWARE New Content Inside condition "); 
     //AJS.$(".field-group").children('label[for=description]').append('<span class="aui-icon icon-required"></span>'); 
     break; 

     // DEFAULT CASE ALWAYS RUNS. 

    default: 
     console.log("A new workflow scheme is detected. Need to update the Scripts Plugin in Create Issue Screens"); 
    } 

    var workflowSchemeName = 'HW Workflow Scheme'; 

    switch (workflowSchemeName) { 

     // FAILING HERE 
    case "SW Work Flow Scheme": 
     console.log("SOFTWARE New Content Inside condition "); 
     //AJS.$(".field-group").children('label[for=description]').append('<span class="aui-icon icon-required"></span>'); 
     //AJS.$(".field-group").children('label[for=customfield_10105]').append('<span class="aui-icon icon-required"></span>'); 
     break; 

    case "HW Workflow Scheme": 
     console.log("HARDWARE New Content Inside condition "); 
     //AJS.$(".field-group").children('label[for=description]').append('<span class="aui-icon icon-required"></span>'); 
     break; 

     // DEFAULT CASE ALWAYS RUNS. 

    default: 
     console.log("A new workflow scheme is detected. Need to update the Scripts Plugin in Create Issue Screens"); 
    } 

Die Ausgabe lautet:

"SOFTWARE New Content Inside condition " 
"HARDWARE New Content Inside condition "