调用Worklight Adapter并将列表视图中的JSON数据显示为字符串 [英] Invoking Worklight Adapter and Displaying that JSON data in list view as strings

查看:104
本文介绍了调用Worklight Adapter并将列表视图中的JSON数据显示为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的adapter.impl.js代码。

This is my adapter.impl.js code.

 //This procedure implementation is to get all the details from the table which in database.
 var procedure1Statement = WL.Server.createSQLStatement("select * from employee");
 function procedure1() {
return WL.Server.invokeSQLStatement({
    preparedStatement : procedure1Statement,
    parameters : []
});
}

这是我在工作光中从SQL Adapter检索到的JSON数据。

This is my JSON data retrieved from SQL Adapter in worklight.

{
"isSuccessful": true,
"resultSet": [
  {
     "EMAIL": "bkandregula@gmail.com",
     "ID": 1,
     "NAME": "Bhanu Kandregula"
  },
  {
     "EMAIL": "rbkandregula@gmail.com",
     "ID": 2,
     "NAME": "Raghu Kandregula"
  },
  {
     "EMAIL": "shyamsurisetty@gmail.com",
     "ID": 3,
     "NAME": "Shyam Surisetty"
  },
  {
     "EMAIL": "bunny@gmail.com",
     "ID": 4,
     "NAME": "Bunny"
  },
  {
     "EMAIL": "divya@gmail.com",
     "ID": 5,
     "NAME": "Divya Sri"
  },
  {
     "EMAIL": "chandhu@gmail.com",
     "ID": 6,
     "NAME": "Chandana"
  }
]
}

我不是从客户端调用此适配器并在移动设备c的列表视图中显示此数据onsole。为此,这是我在客户端js文件中使用的ccode。

Not I was to invoke this adapter from Client side and display this data in list view on my mobile console. For that, this is the ccode which i used in client side js file.

function wlCommonInit(){
LoadSQLRecords();}

function loadSQLRecords(){
var invocationData = {
    adapter : 'MySQLadap',
    procedure : 'procedure1',
    parameters : []
};

WL.Client.invokeProcedure(invocationData,{
    onSuccess : loadSQLQueerySuccess,
    onFailure : loadSQLQueeryFailure
});
}

function loadSQLQueerySuccess(result){
WL.Logger.debug("Retrieve success" +  JSON.stringify(result));
displayFeeds(result.invocationResult.resultSet);
}



function loadSQLQueeryFailure(result){
WL.Logger.error("Retrieve failure");
}

function displayFeeds(items){
var ul = $('#itemsList');
for (var i = 0; i < items.length; i++) {
     var li = $('<li/>').html(items[i].id);
     li.append($('<li/>').html(items[i].name));
     li.append($('<li/>').html(items[i].email));
     li.append($('<hr>'));
     ul.append(li);
   }
  }

这是我的HTML文件代码,用于显示我的数据屏幕。

And this my HTML file code to display my data on screen.

<div id="wrapper">
        <ul id="itemsList"></ul>
 </div>

但这不适用于我。我一直在搜索许多博客和网站,但我无法触发这个。 pease帮助我调用适配器并在移动控制台的列表视图中显示该数据。谢谢。

But This is not working with me. I have been searching many blogs and sites, But I was unable to trigger this. pease do help me in invoking adapter and display that data in list view on mobile console. Thank you.

推荐答案

您需要更正以下内容,然后重新部署该应用程序。

You need to correct the below and then re-deploy the application.


  1. 您拼错了一个函数名称:

  1. You have misspelled a function name:

LoadSQLRecords 应该是 loadSQLRecords

function wlCommonInit(){
    LoadSQLRecords(); // Upper-case 'L'; should be lower-case.
}

function loadSQLRecords(){
    var invocationData = {
        adapter : 'MySQLadap',
        procedure : 'procedure1',
        parameters : []
    };
};

您应该在修复之前在Chrome DevTools控制台中看到以下内容:

You should have seen the following in the Chrome DevTools' console prior to the fix:

worklight.js:5147 Uncaught Exception: Uncaught ReferenceError: LoadSQLRecords is not defined at (compiled_code):4
main.js:4 Uncaught ReferenceError: LoadSQLRecords is not defined


  • 您需要更改以下内容才能实际显示任何值。

  • You need to change the following in order to actually display any values.


    • 使用 items.invocationResult.resultSet

    • 为物业使用正确的大写字母


    来自:

    for (var i = 0; i < items.length; i++) {
        var li = $('<li/>').html(items[i].id);
        li.append($('<li/>').html(items[i].name));
        li.append($('<li/>').html(items[i].email));
        li.append($('<hr>'));
        ul.append(li);
    }
    

    收件人:

    for (var i = 0; i < items.invocationResult.resultSet.length; i++) {
        var li = $('<li/>').html(items.invocationResult.resultSet[i].ID);
        li.append($('<li/>').html(items.invocationResult.resultSet[i].NAME));
        li.append($('<li/>').html(items.invocationResult.resultSet[i].EMAIL));
        li.append($('<hr>'));
        ul.append(li);
    }
    


  • 这篇关于调用Worklight Adapter并将列表视图中的JSON数据显示为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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