将来自适配器的JSON响应填充到下拉菜单中


Populating JSON response from adapter into Drop down menu

我正在通过适配器获取JSON响应。如何将其填充到下拉列表中。我尝试在HTML代码中插入php代码。但它打印代码是有帮助的。

 HTML Code:

 <!DOCTYPE HTML>
    <html>
       <head>
              <meta charset="UTF-8">
              <title>TestApp</title>
              <meta name="viewport" content="width=device-width, initial-scale=1.0,
    maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
              <link rel="shortcut icon" href="images/favicon.png">
              <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
              <link rel="stylesheet" href="css/TestApp.css">
              <script>window.$ = window.jQuery = WLJQ;</script>

       </head>
       <body id="content" style="display: none;">
              <!--application UI goes here-->
              SOWRUN APP</br>

    <p> employeenumber: <input type="text" id="employeenumber"/></br>

    <p><br>employeename:       <input type="text" id="employeename"/></br></p>
    <p><br>employeeemail:      <input type="text" id="employeeemail"/></br></p>
    <p><br>employeeadID:       <input type="text" id="employeeadID"/></br></p>
    <p><br>businessUnit:       <input type="text" id="businessUnit"/></br></p> 
    <select name="country" id="country">
    <option>Select Country</option>
    <option>INDIA</option>
    <option>USA</option>
    </select>

              <p><br>city:               <input type="text" id="city"/>      </br></p>
             <p><br>location:           <input type="text"       id="location"/>
               <p><br>bloodGroup:         <input type="text"   id="bloodGroup"/>
                <p><br>gender:               <input type="text" id="gender"/></br></p>
              <p><br>tShirt:                    <input type="text" id="tShirt"/>

     <input type="button" onclick="submitName()" value="Submit"/></br>

              <script src="js/initOptions.js"></script>
              <script src="js/TestApp.js"></script>
              <script src="js/messages.js"></script>
       </body>
  </html>

我希望将以下JSON响应填充到"country"下拉列表中,该列表是我从适配器中获得的。

JSON响应:过程的调用结果:Worklight Server中的"getCountrys":

{
 "array": [
      {
         "con_name": "India"
      },
      {
         "con_name": "Portugal"
      },
      {
         "con_name": "Spain"
      },
      {
         "con_name": "UAE"
      },
      {
         "con_name": "USA"
      },
      {
         "con_name": "Mexico"
      },
      {
         "con_name": "Australia"
      },
      {
         "con_name": "Romania"
      },
      {
         "con_name": "Phillipines"
      },
      {
         "con_name": "Netherlands"
      },
      {
         "con_name": "UK"
      },
      {
         "con_name": "Singapore"
      },
      {
         "con_name": "Switzerland"
      },
      {
         "con_name": "Hungary"
      },
      {
         "con_name": "USAWest"
      },
      {
         "con_name": "USA South"
      },
      {
         "con_name": "Mexico"
      },
      {
         "con_name": "Brazil"
      },
      {
         "con_name": "China"
      },
      {
         "con_name": "NewZealand"
      },
      {
         "con_name": "Poland"
      },
      {
         "con_name": "Japan"
      },
      {
         "con_name": "Germany"
      },
      {
         "con_name": "Canada"
      },
      {
         "con_name": "France"
      },
      {
         "reg_AD_ID": "111111"
      }
   ],
   "isSuccessful": true,
   "responseHeaders": {
      "Connection": "Keep-Alive",
      "Content-Length": "594",
      "Content-Type": "text'/html",
      "Date": "Mon, 29 Jul 2013 07:01:37 GMT",
      "Keep-Alive": "timeout=5, max=100",
      "Server": "Apache'/2.2.21 (Win32) PHP'/5.3.8",
      "X-Powered-By": "PHP'/5.3.8"
   },
   "responseTime": 85,
   "statusCode": 200,
   "statusReason": "OK",
   "totalTime": 85
}

您创建了一个适配器SQL,对吗?

在js中,您有一个适配器过程,例如:

    function procedureXX(param){
        var invocationData={
                adapter : 'NameAdapter',
                procedure: 'procedureXMLName',
                parameters:[param]
        };
        WL.Client.invokeProcedure(invocationData,
                {
            onSuccess: function(result){
                onSuccessFunc(result);
            },
            onFailure: function(){
                WL.Logger.debug("failed");
            }
            }       
    );
}

在函数onSuccessFunc中,您可以使用innerHTml 设置下拉菜单

  function onSuccessSelectAllCodiciClienti(result){
        if (result.invocationResult.resultSet.length>0) {
            var cod=result.invocationResult.resultSet;
            var select=.....
            for (var i=0;i<cod.length;i++){
                select+=" ... cod["+i+"].con_name} ... ";
            }

        }
        var vText = document.getElementById("drop_down_menu_HTML_id");
    vText.innerHTML = select;
    }