IBM Worklight - 如何解析适配器响应? [英] IBM Worklight - How to parse adapter response?

查看:178
本文介绍了IBM Worklight - 如何解析适配器响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的存储过程:

CREATE PROCEDURE PROC()
BEGIN
SELECT * FROM TABLENAME;
END//

这是我使用SQL适配器调用存储过程的功能:

This is my unction to call stored procedure using SQL adapter:

function callStored() {
    return WL.Server.invokeSQLStoredProcedure({
        procedure : "proc",
        parameters : []
    });
}

这是invocationResult:

This is the invocationResult:

{
   "isSuccessful": true,
   "resultSet": [
      {
         "name": "a",
         "pass": "123",
         "time_stamp": "2014-04-07T10:13:17.000Z"
      },
      {
         "name": "chetan",
         "pass": "123456",
         "time_stamp": "2014-04-07T10:13:34.000Z"
      },
      {
         "name": "dileep",
         "pass": "456321",
         "time_stamp": "2014-04-07T10:13:54.000Z"
      },
      {
         "name": "bnc",
         "pass": "654321",
         "time_stamp": "2014-04-07T10:19:37.000Z"
      }
   ]
}

我需要解析这个并显示或提醒 name的值传递 time_stamp

I need to parse this and display or alert the values of name, pass and time_stamp.

我如何做到这一点?

推荐答案

在你身边r应用程序JavaScript(common \ js \ main.js),您可以使用以下内容。在下面的代码中,将显示一个警告,其中包含来自resultSet的 name 键的值。

In your application JavaScript (common\js\main.js), you can have something like the following. In the below code an alert will be displayed with the values of the name key from the resultSet.

你可以另请看这里:使用返回的结果集sql adapter程序中的WL.Server.invokeSQLStatement

function wlCommonInit() {
    invokeAdapter();
}

function invokeAdapter() {
    var invocationData = {
        adapter: "your-adapter-name",
        procedure: "callStored",
        parameters: []
    };

    WL.Client.invokeProcedure (invocationData, {
        onSuccess: invocationSuccess,
        onFailure: invocationFailure}
    );
}

function invocationSuccess(response) {
    var i,
        resultSet = response.invocationResult.resultSet;
        namesArray = [];

    for (i = 0; i < resultSet.length; i++) {
        namesArray[i] = resultSet[i].name;
    }
    alert (JSON.stringify(namesArray));
}

function invocationFailure(response) {
   alert (response);
}

您已在此处提出此问题:ibm worklight存储过程

为什么不按照文档进行操作并学习如何编写上述内容?

You have already asked this here: ibm worklight stored procedure
Why did you not follow through the documentation and learned how to write the above?

请阅读文档!

这篇关于IBM Worklight - 如何解析适配器响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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