0

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

 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 响应填充到我从适配器获取的“国家”下拉列表中。

JSON 响应:过程的调用结果:来自 Worklight Server 的“getCountries”:

{
 "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
}
4

1 回答 1

1

您创建了一个适配器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;
    }
于 2013-07-29T12:24:30.400 回答