无法从Lightning组件的帮助器类调用Apex控制器

时间:2019-05-16 01:27:51

标签: salesforce salesforce-lightning

我正在创建一个只有一个按钮的基本闪电组件。单击此按钮后,我正在调用返回字符串的apex方法。 由于某些原因,每当我单击该按钮时,都不会得到任何回应。在控制台,闪电事件日志和调试日志中,我没有收到任何错误。我不知道发生了什么以及如何调试它。请帮忙。

我尝试在事件日志,调试日志和控制台上对其进行调试。无法弄清楚。请帮忙!

            COMPONENT: 
            <aura:component controller="CustomMassDownload" implements="force:appHostable,force:hasRecordId,flexipage:availableForAllPageTypes,force:lightningQuickAction" access="global" > 

                <div class="slds-p-top_xx-large">
                       <button type="button" onclick="{!c.downloadFile}" >Download</button> 
                </div>
            </aura:component>

            CONTROLLER:
            ({
                downloadFile : function(component, event, helper) {
                    console.log('why?');
                    helper.getString(component,event,helper);
                }
            })

            HELPER:

            ({
getString : function(component,event,helper) {
    console.log('owl');
    var action = component.get("c.ReturnString");
    action.setParams({
        abc: "djflskj"
    });
    console.log('puppy' + action);
    action.setCallback(this,function(response){
        console.log('issuccess');
        var state = response.getState();
        if(state === "SUCCESS"){
            console.log('love');
        }else{
            console.log('hate');
        }
    });

}

})                 APEX:

            public class CustomMassDownload{

                @AuraEnabled
                public static String ReturnString(String abc){
                system.debug('aaaaaaaaaa');
                return abc;
                }
            }

1 个答案:

答案 0 :(得分:1)

进一步查看代码后,我发现您实际上并没有在调用apex控制器。

您需要将$A.enqueueAction添加到getString中。

getString : function(component,event,helper) {
    console.log('owl');
    var action = component.get("c.ReturnString");
    action.setParams({
        abc: "djflskj"
    });
    console.log('puppy' + action);
    action.setCallback(this,function(response){
        console.log('issuccess');
        var state = response.getState();
        if(state === "SUCCESS"){
            console.log('love');
        }else{
            console.log('hate');
        }
    });
    $A.enqueueAction(action);
}