简体   繁体   English

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

[英]Not able to call apex controller from lightning component's helper class

I am creating a basic lightning component which got just one button. 我正在创建一个只有一个按钮的基本闪电组件。 On click of this button, I am calling an apex method which return a string. 单击此按钮后,我正在调用返回字符串的apex方法。 For some reason, whenever I am clicking that button, I get no response. 由于某些原因,每当我单击该按钮时,都不会得到任何回应。 In the console, lightning event log and debug log, I get no error. 在控制台,闪电事件日志和调试日志中,我没有收到任何错误。 I have no idea as whats going on and how to debug this. 我不知道发生了什么以及如何调试它。 Please help. 请帮忙。

I tried debugging it on the event log, debug log and the console. 我尝试在事件日志,调试日志和控制台上对其进行调试。 Not able to figure out. 无法弄清楚。 Please help! 请帮忙!

            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;
                }
            }

After further looking at your code I see you are not actually calling your apex controller. 进一步查看您的代码后,我发现您实际上并没有在调用apex控制器。

You need to add $A.enqueueAction to your getString . 您需要将$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);
}

暂无
暂无

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

相关问题 如何将Javascript映射作为参数从闪电组件发送到Apex服务器控制器? - How to send Javascript map as a parameter from lightning component to Apex server controller? 在没有顶点的闪电 web 组件上创建任务仅 javascript controller? - Create a task on a lightning web component without apex only javascript controller? 有没有办法从闪电 Web 组件(LWC)中的 JS 将多个(和不同的)参数传递给 Apex Controller class? - Is there a way to pass multiple (and different) parameters to an Apex Controller class from JS in Lightning Web Components (LWC)? Salesforce Lightning Component不会通过Apex调用更新记录,从而冻结 - Salesforce Lightning Component will not update records via Apex call, freezes JSON 从 Apex 传递到 Lightning 组件并在数据表中显示 - JSON to be passed from Apex to Lightning Component and display it in a data table 呼叫同一雷电组件内部的雷电组件 - Call lightning component inside same lightning component Lightning-record-view 表单不显示具有从顶点 class 获取的 id 的记录。 Salesforce LWC,Apex - Lightning-record-view form is not displaying the record with the id that is fetch from an apex class. Salesforce LWC,Apex Apex组件控制器无法从apex:inputText / inputField获取值 - Apex Component Controller can not get value from apex:inputText/inputField 控制器未从闪电组件初始化处理程序接收对象 - Controller not receiving Object from Lightning Component Init Handler 从 URL 调用闪电 Web 组件并从 URL 捕获参数 - Call lightning Web Component from URL and capture parameter from URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM