IBM Worklight - 如何将参数从应用程序传递到适配器?

时间:2013-07-25 07:39:00

标签: javascript ibm-mobilefirst worklight-adapters

我想将参数从应用程序传递到适配器;我希望应用程序的用户输入这些选项。

现在我在适配器中传递这样的参数:

    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 个答案:

答案 0 :(得分:1)

您可以使用简单的JavaScript传递参数 例如:

<强> 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");
}

适配器XML

<procedure name="showParameters"/>

适配器实施

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

要实际查看记录的行,您需要:

  1. 在Eclipse中打开Servers视图
  2. 扩展Worklight Development Server条目
  3. 双击Server Configuration
  4. 点击Logging
  5. 将控制台日志级别从AUDIT更改为INFO(使用下拉列表)

    全尺寸图片:http://i.stack.imgur.com/9llHc.png enter image description here

  6. 您可能需要Project&gt;&gt;清洁...

  7. 结果将显示在Worklight Development Server的控制台视图中

    全尺寸图片:http://i.stack.imgur.com/x2Hv1.png enter image description here