0

I am trying to do this, but nothing works ... I am a beginner.

//helper js

getDataFromDB : function(component){
    let action = component.get('c.getListContacts');
    action.setCallback(this, function(response){
       let state = response.getState();
           if (state === "SUCCESS") {
               let rows = response.getReturnValue();
                component.set("v.contacts", rows);
            }
    });
    $A.enqueueAction(action);
    this.calculateAmountPage(component);
    this.getDisplayDataPagination(component);

},

Methods "calculateAmountPage" and "getDisplayDataPagination" are located below in the same helper.js file.

1 Answer 1

3

You need to use the helper reference to access those functions. To do so:

Accept the helper reference in the helper function

getDataFromDB : function(component, event, helper){

And pass it in by accepting the helper reference in the controller function. e.x.

onButtonClick : function(component, event, helper){
  getDataFromDB(component, event, helper);
}

Then call the other functions like this

helper.calculateAmountPage(component);
helper.getDisplayDataPagination(component);
4
  • Maybe I misunderstood, but my getDataFromDB : function(component){ function is already in "helper.js". And from it I need to call other functions, which are also already in "helper.js". I know how to call the functions located in "helper.js" from the controller. Commented Mar 12, 2021 at 18:01
  • I cannot call all functions from helper.js from the controller, because they will run at the same time and I will get an error. I need to call a helper function, which in turn will call another helper function at the end of its execution. Commented Mar 12, 2021 at 18:09
  • Are you calling getDataFromDB from the controller? If so, pass in helper and then you will have a reference to all helper methods from within getDataFromDB (and you can in turn pass the helper reference to other helper functions) Commented Mar 12, 2021 at 18:23
  • Wow! With a little experimenting I got it. I understood. I didn't know it was possible! Thank you very much! Commented Mar 12, 2021 at 20:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .