简体   繁体   English

无法调用适配器过程

[英]Unable to invoke adapter procedure

I'm using IBM MobileFirst to create an app. 我正在使用IBM MobileFirst创建一个应用程序。 I've created an HTTP Adapter and now I'm working on the invocation of the response within my main.js file. 我已经创建了一个HTTP适配器,现在我正在main.js文件中调用响应。 Here is the invokeProcedure call (the invocationData var calls the adapter and the procedure within that adapter): 这是invokeProcedure调用(invocationData var调用适配器以及该适配器中的过程):

    WL.Client.invokeProcedure(invocationData,{
       onSuccess : loadSuccess(),
       onFailure : loadFailure(),
    });

Now, I've defined a loadSuccess() and a loadFailure() function (declared before the invocation) as such (simple for testing purposes): 现在,我已经这样定义了loadSuccess()和loadFailure()函数(在调用之前声明)(为测试目的而简单):

    var loadSuccess = function(result){
       alert("success");
       alert(result.invocationResult);
    }

    var loadFailure = function(result){
       alert("failure");
       alert(result.invocationResult);
    }

However, while "success" and "failure" will flash, "result" is coming back as null. 但是,虽然“成功”和“失败”将闪烁,但“结果”将返回为空。 Every tutorial I have seen as used these methods with success, so I am confused as to why my similar implementation is not working. 我看过的每个教程都成功地使用了这些方法,因此我对为什么我的类似实现无法正常工作感到困惑。 Furthermore, the invokeProcedure function seems to be calling and flashing the results of both the success and failure options! 此外,invokeProcedure函数似乎正在调用并刷新成功和失败选项的结果!

My adapter returns an appropriate response when I just test that, so why isn't the invocation of the data working correctly? 当我刚刚测试适配器时,适配器会返回一个适当的响应,那么为什么数据调用不能正常工作? IBM documentation is not very clear, so I appreciate any and all suggestions! IBM文档不是很清楚,因此,我感谢所有建议!

EDIT: 编辑:

I updated main.js to the following code: 我将main.js更新为以下代码:

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

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

 function testFunc(userid, password) {
     var invocationData = {
        adapter : 'myAdapter',
        procedure : 'myProc',
        parameters : [ userid, password ],
    };

    WL.Client.invokeProcedure(invocationData,{
       onSuccess : loadSuccess,
       onFailure : loadFailure
   });
}

When I test my adapter, by simply calling it, the response is successful and contains all the response information I want. 当我测试适配器时,只需调用它,响应就成功了,并且包含了我想要的所有响应信息。 So why isn't onSuccess being called here? 那么,为什么在这里不调用onSuccess?

Likely you need to remove the param brackets from the onSuccess and onFailure declarations, otherwise it runs the functions when assigned rather than when needed: 可能您需要从onSuccess和onFailure声明中删除参数括号,否则它会在分配时而不是在需要时运行函数:

WL.Client.invokeProcedure(invocationData,{
   onSuccess : loadSuccess,
   onFailure : loadFailure
});

Since you're using "var" to define your onSuccess/onFailure callbacks make sure they're in the same scope. 由于您使用“ var”来定义onSuccess / onFailure回调,因此请确保它们在同一作用域内。 Try providing inline callbacks, eg 尝试提供内联回调,例如

WL.Client.invokeProcedure(invocationOptions, {
   onSuccess: function(data){ alert....},
   onFailure: function(data){ alert....}
})

You have to declare initOptions.js , main.js and messages.js in the html file that will use the controller that points to your adapter .. 您必须在html文件中声明initOptions.js,main.js和messages.js,这些文件将使用指向适配器的控制器..

else the invokeProcedure will be undifined 否则invokeProcedure将是未定义的

just go to your html file and but this code in the end of body tag directly before closing tag 只需转到您的html文件,但是此代码直接在结束标记之前位于body标记的末尾

<script src="js/initOptions.js"></script>
<script src="js/main.js"></script>
<script src="js/messages.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM