IBM Worklight - How to pass parameters from the application to the adapter?

二次信任 提交于 2019-12-02 13:40:07

问题


I want to pass parameters from the application to the adapter; I want the users of the app to enter these options.

Right now I am passing the parameters like this in adapter:

    function getFeeds() {
        WL.Logger.debug("inside method");

        var input = {
            method : 'get',
            returnedContentType : 'json',
            path : "ios/clientRegister.php",
            parameters:{
              "employeenumber":"500","employeename":"Harish","employeeemail":"anand5@gmail.com","city":"Delhi", 
              "employeeadID":"an6458","businessUnit":"WASE","country":"India","city":"Bengaluru","location":"EC4","bloodGroup":"B+ve", "gender":"Male","tShirt":"xl"    
            }  
        };
        return WL.Server.invokeHttp(input);
    }

回答1:


You can pass the parameters using simple JavaScript.
For example:

HTML

First name: <input type="text" id="firstname"/>
Last name: <input type="text" id="lastname"/>
<input type="button" onclick="submitName()" value="Submit Name"/>

App JS

function submitName() {
    var invocationData = {
            adapter : 'exampleAdapter',
            procedure : "showParameters",
            parameters : [$('#firstname').val(),$('#lastname').val()]
    };

    var options = {
            onSuccess : success,
            onFailure : failure
    };

    WL.Client.invokeProcedure(invocationData, options);
}


function success() {
    alert ("success");
}

function failure() {
    alert ("failure");
}

Adapter XML

<procedure name="showParameters"/>

Adapter implementation

function showParameters(firstname, lastname) {
    WL.Logger.info  ("The submitted parameters are: '" + firstname + "' and '" + lastname + "'");
}

To actually see the logged line you'll need to:

  1. Open the Servers view in Eclipse
  2. Expend the Worklight Development Server entry
  3. Double-click on Server Configuration
  4. Click on Logging
  5. Change the Console log leve from AUDIT to INFO (using the dropdown)

    Full size image: http://i.stack.imgur.com/9llHc.png

  6. You may need to Project >> Clean...

  7. The outcome will be in the Console view for the Worklight Development Server

    Full size image: http://i.stack.imgur.com/x2Hv1.png



来源:https://stackoverflow.com/questions/17851867/ibm-worklight-how-to-pass-parameters-from-the-application-to-the-adapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!