You need to sign in to do that
Don't have an account?
Flint Lockwood
Function Order of Operation in Lightning
I am passing the return value from one function in another function in Lightning (sample below). However, the return value from the first function is always undefined.
myfunction1: function(component) { //call an Apex method //return result of apex method } myfunction2: function(component) { var result = this.myfunction1(component); console.log(result) //RESULT IS ALWAYS UNDEFINED }
The lightning framework works in an asynchronous fashion. So, when you call the function1 method from function2, it will just enqueue it and not actually execute it at that point. They are just churned out into multiple threads. You will have to put the logic you intend to put in function2 within the callback function of function1.
myfunction1: function(component)
{
//call an Apex method
//return result of apex method
//function2 logic should be executed here in the CallBack method here.
}
myfunction2: function(component)
{
var result = this.myfunction1(component);
console.log(result) //RESULT IS ALWAYS UNDEFINED
}
That should work !
All Answers
myfunction1: function(component)
{
//call an Apex method
//return result of apex method
var result = {return result of apex method}
myfunction2(result)
}
myfunction2: function(component,result)
{
//var result = this.myfunction1(component);
console.log(result) //RESULT IS ALWAYS UNDEFINED
}
The lightning framework works in an asynchronous fashion. So, when you call the function1 method from function2, it will just enqueue it and not actually execute it at that point. They are just churned out into multiple threads. You will have to put the logic you intend to put in function2 within the callback function of function1.
myfunction1: function(component)
{
//call an Apex method
//return result of apex method
//function2 logic should be executed here in the CallBack method here.
}
myfunction2: function(component)
{
var result = this.myfunction1(component);
console.log(result) //RESULT IS ALWAYS UNDEFINED
}
That should work !