在worklight中从服务器返回一组resultSets [英] Return an array of resultSets from the server in worklight

查看:82
本文介绍了在worklight中从服务器返回一组resultSets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用resultSet中返回的多行中的值来反复调用过程并在主html页面上显示调用过程的结果

I want to use the values from multiple rows returned in a resultSet to invoke a procedure again and again and display the result of the invoked procedure on main html page

适配器JS

var selectStatement = WL.Server.createSQLStatement("select * from medicine WHERE Name= ? ");
var selectStatement2 = WL.Server.createSQLStatement("select LocId from location WHERE LocName= ? ");
var selectStatement3 = WL.Server.createSQLStatement("select RegNo from storeloc WHERE LocId= ? ");
var selectStatement4 = WL.Server.createSQLStatement("select RegNo from stormedavl where RegNo=? AND (MedId=? AND Availability=true)");
var selectStatement5 = WL.Server.createSQLStatement("select * from store WHERE RegNo= ? ");



function getMedicineDetails1(Name,Location) { 
var a=getMedicineDetails(Name);
var MedId=a.resultSet;
var b=getLocId(Location);
var LocId=b.resultSet;
var c=getRegNo(LocId[0].LocId);
var cc=c.resultSet;
 //here c.resultSet contains two rows 
 var d={},e;
 if(cc && cc.length>0)
 {
    for(var i=0;i<c.resultSet.length;i++)
        {
            d[i]=getFinal(cc[i].RegNo,MedId[0].MedId);


        }
    return d;


}

}
function getMedicineDetails(Name) {    

   return WL.Server.invokeSQLStatement({
        preparedStatement : selectStatement,
        parameters : [Name]
    });
}
function getLocId(Location) {  
    return WL.Server.invokeSQLStatement({
        preparedStatement : selectStatement2,
        parameters : [Location]
    });
} 
    function getRegNo(LocId) {  
    return WL.Server.invokeSQLStatement({
        preparedStatement : selectStatement3,
        parameters : [LocId]
    });   



}
    function getFinal(RegNo,MedId) {    
           return WL.Server.invokeSQLStatement({
            preparedStatement : selectStatement4,
            parameters : [RegNo,MedId]
        });
    }

    function getStoreDetails(RegNo) {  
        return WL.Server.invokeSQLStatement({
            preparedStatement : selectStatement5,
            parameters : [RegNo]
        });   



    } 

JS文件

    window.$ = window.jQuery = WLJQ;
 function wlCommonInit() {

 }
 $(document).ready(function(){

$("#search").click(function(){
GetEmployeeData();

});



 });

 var med;

 function GetEmployeeData() {

var medicine= $("#medicine").val();
var location=$("#location").val();
alert(medicine);

var invocationData = {
    adapter : 'ATM',
    procedure : 'getMedicineDetails1',
    parameters: [medicine,location]
};

WL.Client.invokeProcedure(invocationData,{
    onSuccess : loadFeedsSuccess,
    onFailure : loadFeedsFailure
});



 }
 function loadFeedsSuccess(result){

  alert("Hii");
 WL.Logger.debug("Feed retrieve success");

if (result.invocationResult.resultSet.length>0) 
{

    displayFeeds2(result.invocationResult.resultSet);
}
else 
    loadFeedsFailure();

 }

  function loadFeedsFailure(result){


alert("Values Not Found in DB");
 }
  function displayFeeds2(items){
alert("ii");
var table = document.getElementById("myTable1");
for(var i=0;i<items.length;i++)
    {
    var row = table.insertRow(i+1);

    // Insert new cells (<td> elements) at the 1st and 2nd position of the    "new" <tr> element:
    var cell1 = row.insertCell(0);
    cell1.innerHTML = items[i].RegNo;
    }

    }
  function LoadResultPage()
  {
  $("AppDiv").hide();

  $("#itemsList").show();
  };

HTML FILE

HTML FILE

<!DOCTYPE HTML>
<html>
        <head>
            <meta charset="UTF-8">
            <title>ATM</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/ATM.css">
            <script>window.$ = window.jQuery = WLJQ;</script>
        </head>
        <body id="content" style="display: none;">
            <!--application UI goes here-->
    <div id="AppDiv">   
<h1> <img border="0" src="images/atm.png" width="50" height="50" align="middle">
<font color='white'> ANY TIME MEDICINE </font> 
</h1>
<br>
<div data-role="page" id="mainPage">
    <div data-role="header">search medicine
    </div><br>

        <hr>
        <div data-role="content">       
        <input type="text" value="MEDICINE" id="medicine"><hr>
        <input type="text" value="LOCATION" id="location"><hr>
        <input type="submit" id="search" value="SEARCH">
        </div>
</div>
<div id="itemsList" data-role="page">

<table id="myTable1" border="1">
<tr>
<th>Registration No</th>
</tr>
</table>
    <div data-role="header">gg
    </div>
    <div data-role="content">
    </div>
</div>

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

问题是在输出处我们只得到一个RegNo(注册号)而不是两个从循环中调用getFinal适配器过程的结果。我想问一下我们可以存储getFinal过程调用结果的方式,然后在html页面上显示它们。基本上我想问一下我们是否可以从服务器返回一个resultSets数组客户端。

The problem is that at the output we get only one RegNo(registration no )instead of two as a result of calling getFinal adapter procedure from the loop.I want to ask the way we can store the result of invocations of getFinal procedure and then displat them at the html page.Basically i want to ask if we can return an array of resultSets from server to he client.

推荐答案

您需要做的是将getRegNo中的两个结果集与getFinal进行混搭。
以下是如何从服务器获取resultSets数组

What you need to do is to mashup both result sets from the getRegNo with the getFinal. Here is how to get an array of resultSets from the server

更改您的代码:

//here c.resultSet contains two rows 
var d={},e;
if(cc && cc.length>0) {
    for(var i=0;i<c.resultSet.length;i++) {
        d[i]=getFinal(cc[i].RegNo,MedId[0].MedId);
    }
    return d;
}

在您的代码中,您将获得类似 {0 :'regNo_1',1:'regNo_2'} 其中整数是 d [i]

in your code you will get something like {0 : 'regNo_1', 1 : 'regNo_2'} where the integer is d[i]

to:

    //here c.resultSet contains two rows
    if (cc && cc.length > 0) {
        for (var i = 0; i < cc.length; i++) {
            cc[i].regNo = getFinal(cc[i].RegNo,MedId[0].MedId);
        }
        return {'regNos' : cc};
    }
}

为了得到一系列看起来很像的结果集像这样:

In order to get an array of resultSets that will look like this:

{
   "regNos": [
      {
         "regNo": 12345,
         "regNo": {
            "isSuccessful": true,
            "regNo": [
               {
                  "regNo": "1"
               }
            ]
         }
      },
      {
         "regNo": 54321,
         "regNo": {
            "isSuccessful": true,
            "resultSet": [
               {
                  "regNo": "2"
               }
            ]
         }
      }
   ],
   "isSuccessful": true
}

这篇关于在worklight中从服务器返回一组resultSets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆