【问题标题】:IBM Worklight - How to pass parameters from the application to the adapter?IBM Worklight - 如何将参数从应用程序传递到适配器?
【发布时间】:2013-07-25 07:39:00
【问题描述】:

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

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

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

【问题讨论】:

    标签: javascript ibm-mobilefirst worklight-adapters


    【解决方案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"/>
    

    应用 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 中打开服务器视图

    2. 扩展Worklight Development Server 条目

    3. 双击Server Configuration

    4. 点击Logging

    5. 将控制台日志级别从 AUDIT 更改为 INFO(使用下拉菜单)

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

    6. 你可能需要 Project >> Clean...

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

      全尺寸图片:http://i.stack.imgur.com/x2Hv1.png

    【讨论】:

    • 请分享有关如何查看记录的数据/行的信息。我必须在所有其他测试用例中使用它来分析工作灯的行为。非常感谢....
    • 这取决于您的 Worklight 版本。您的 Worklight 版本是什么?请参阅我更新的答案以及 Worklight 6.0 的说明。无论如何,如果我的回答帮助您理解了如何传递参数(这就是这个问题的意义所在),请标记为已回答。谢谢!
    • 再次感谢 Idan Adar 提供的宝贵信息。
    • 如何在选项中使用验证以及如何获得一个选定项目的下拉菜单(就像我们在 android 中使用微调器一样)。
    • 与此问题无关(也与 Worklight 无关)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多