IBM Worklight - 无法显示使用SQL适配器检索的数据 [英] IBM Worklight - Unable to display data retrieved using SQL adapter

查看:125
本文介绍了IBM Worklight - 无法显示使用SQL适配器检索的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从数据库获取数据并在应用程序中显示。

下面是我的代码。

  var selectStatement = WL.Server.createSQLStatement(select * from studentinfo); 

function getStudentInfos(){
return WL.Server.invokeSQLStatement({
preparedStatement:selectStatement,
parameters:[]
});
}

sqlAdapter.js
$ b

 窗口$ = window.jQuery = WLJQ; 

function wlCommonInit(){
GetEmployeeData();
}

函数GetEmployeeData(){
var invocationData = {
adapter:'sqlAdapter',
procedure:'getStudentInfos'
} ;

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

function loadFeedsSuccess(result){
WL.Logger.debug(Feed retrieve success);
busyIndi​​cator.hide();
if(result.invocationResult.Items.length> 0)
displayFeeds(result.invocationResult.Items);
else
loadFeedsFailure();
}

function displayFeeds(items){
var ul = $('#itemsList');
for(var i = 0; i< items.length; i ++){
var li = $('< li />')。html(items [i] .sid);
var pubDate = $('< div />',{'class':'pubDate'})html(items [i] .sname);
li.append(pubDate);
ul.append(li);
}
}

sqlAdapter.html / p>

 < body id =contentstyle =display:none;> 
< div id =itemsList>< / div>

< script src =js / initOptions.js>< / script>
< script src =js / sqlAdapter.js>< / script>
< script src =js / messages.js>< / script>
< / body>

这是我在调用过程时获得的

  {
isSuccessful:true,
resultSet:[
{
sclass:PUC,
sgrade:A +,
sid:PUC001,
sname:Rohan
},
{
sclass:PUC,
sgrade:A,
sid:PUC002,
sname:Rakesh
},
{
sclass:PUC,
sgrade:C,
sid:PUC003,
sname:Raj
},
{
sclass:PUC,
sgrade:E,
sid:PUC004,
sname:Roman
}
]
}

我只是想把所有这些东西都打印在屏幕上

解决方案

首先,你需要改变Items / p>

  if(result.invocationResult.Items.length> 0)
displayFeeds(result.invocationResult.Items);

至resultSet:

  if(result.invocationResult.resultSet.length> 0)
displayFeeds(result.invocationResult.resultSet);



其次,我使用了 worklight_training 数据库脚本Worklight与问题的代码段一起提供。我把 displayFeeds 函数改为:

  function displayFeeds items){
var ul = $('#itemsList'),i,li;

for(i = 0; i< items.length; i + = 1){
//创建新< li>元素并填充它
li = $('< li />')。text(item.firstName);
//附加< li>元素添加到< ul> element
ul.append(li);
}
}

最终结果显示 表中的值。

然后,您可以使用JavaScript更多地显示 资料库表...





BTW,您可以在Chrome开发工具显示某物 ...您在您的情况下声称它不是。你需要弄清楚这一点。


I am trying to fetch data from a database and display it in the app.
Below is my code. The invokation is doing well, but the data is not displayed.

sqlAdapter-impl.js

var selectStatement = WL.Server.createSQLStatement("select * from studentinfo");

function getStudentInfos() {    
    return WL.Server.invokeSQLStatement({
        preparedStatement : selectStatement,
        parameters : []
    });
}

sqlAdapter.js

window.$ = window.jQuery = WLJQ;

function wlCommonInit() {
    GetEmployeeData();
}

function GetEmployeeData() {
    var invocationData = {
        adapter : 'sqlAdapter',
        procedure : 'getStudentInfos'
    };

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

function loadFeedsSuccess(result){
    WL.Logger.debug("Feed retrieve success");
    busyIndicator.hide();
    if (result.invocationResult.Items.length>0) 
        displayFeeds(result.invocationResult.Items);
    else 
        loadFeedsFailure();
}

function displayFeeds(items){
    var ul = $('#itemsList');
    for (var i = 0; i < items.length; i++) {
        var li = $('<li/>').html(items[i].sid);
        var pubDate = $('<div/>', {'class': 'pubDate'}).html(items[i].sname);
        li.append(pubDate);     
        ul.append(li);
    }
}

sqlAdapter.html

<body id="content" style="display: none;">
    <div id="itemsList"></div>

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

this is what I get on invoking the procedure

    {
    "isSuccessful": true,
    "resultSet": [
    {
     "sclass": "PUC",
     "sgrade": "A+",
     "sid": "PUC001",
     "sname": "Rohan"
     },
     {
     "sclass": "PUC",
     "sgrade": "A",
     "sid": "PUC002",
     "sname": "Rakesh"
     },
    {
     "sclass": "PUC",
     "sgrade": "C",
     "sid": "PUC003",
     "sname": "Raj"
     },
     {
     "sclass": "PUC",
     "sgrade": "E",
     "sid": "PUC004",
     "sname": "Roman"
      }
      ] 
      }

I just want all these things to be printed on the screen

解决方案

First, you need to change "Items":

if (result.invocationResult.Items.length>0) 
        displayFeeds(result.invocationResult.Items);

To "resultSet":

if (result.invocationResult.resultSet.length>0) 
        displayFeeds(result.invocationResult.resultSet);


Second, I've used the worklight_training database script Worklight provides in conjunction with your code snippets from the question. I've altered the displayFeeds function to this:

function displayFeeds(items) {
    var ul = $('#itemsList'), i, li;

    for (i = 0; i < items.length; i += 1) {     
        // Create new <li> element and populate it
        li = $('<li/>').text(item.firstName);   
        // Append the <li> element to the <ul> element
        ul.append(li);      
    }
}

The end result was displaying the firstName values from the users table.
You can then play with your JavaScript a bit more to display what you want from your database table...

BTW, as you can see... the console in Chrome Dev Tools does show something... which you claim in your case it does not. You need to figure that out.

这篇关于IBM Worklight - 无法显示使用SQL适配器检索的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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