Edukondalu Thaviti
Edukondalu Thaviti

Reputation: 605

Can I pass two arguments to a Worklight adapter onSuccess function?

I am unable to pass two arguments to the adapter onSuccess() function using IBM Worklight. Please show me the way. Here is what I am currently trying:

var options = {
    onSuccess : SubCategoriesSuccess(options, result),
    onFailure : SubCategoriesFailure,
    invocationContext: {}
};

Upvotes: 2

Views: 80

Answers (2)

tik27
tik27

Reputation: 2698

If options is a variable already on your calling function. You have to wrap the return function in another. So in other words, success is returned from the adapter, and options is just passed along by the calling function.

 onSuccess:function(result){
    SubCategoriesSuccess(options, result);
 }

Upvotes: 0

Andrew Ferrier
Andrew Ferrier

Reputation: 17752

The onSuccess parameter requires a reference to a function, not an invocation of a function - note that there is a difference between SubCategoriesSuccess and SubCategoriesSuccess() in JavaScript. What you are doing is passing the result of calling SubCategoriesSuccess(options, result).

What you need is what is typically referred to as partial invocation in programming jargon. JavaScript itself has a function for doing this - Function.prototype.bind(). You should probably look at that (although there alternatives provided by various JavaScript toolkits too).

This would mean your code would look something like:

{
  onSuccess : SubCategoriesSuccess.bind(this, options, result),
  onFailure : SubCategoriesFailure,
  invocationContext: {}
};

Note that I have not tested this.

Upvotes: 1

Related Questions