[英]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.