获取在Lightning:recordEditForm的onsuccess属性中使用的lightning:button的ID

我想知道是否有一种方法可以获取onsuccess方法中的recordEditForm上单击的按钮的ID。 我试过了 console.log(event.getsource()。getLocalId()); 但这只是返回recordEditForm的ID,而不是单击的按钮。 我需要这个的原因是我想显示两个按钮,一个按钮仅更新案例,另一个按钮更新案例并关闭工作区选项卡

这是组件

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
<lightning:workspaceAPI aura:id="workspace"/>
<aura:attribute name="showSpinner" type="Boolean" default="true"/>
<aura:if isTrue="{!v.showSpinner}">
    <lightning:spinner />
</aura:if>
<div class="slds-box slds-theme_default">
    <div class="slds-text-title_bold">Updates the status to closed and closes the primary tab</div>
    <lightning:recordEditForm aura:id="recordEditor"
                              onload="{!c.handleLoad}"
                              onsubmit="{!c.handleSubmit}"
                              onsuccess="{!c.handleSuccess}"
                              recordId = "{!v.recordId}"
                              objectApiName="Case">
        <lightning:messages />
        <lightning:inputField fieldName="Fault_Category__c" disabled="true" />
        <lightning:inputField fieldName="Fault_Type__c" />
        <lightning:inputField fieldName="Solution__c" />
        <lightning:inputField fieldName="Solution_Details__c" />
        <div class="slds-m-top_medium">
            <lightning:button aura:id="button1" value="value1" variant="brand" type="submit" name="save" label="Close Case and Tab" />
            <lightning:button aura:id="button2" value="value2" variant="brand" type="submit" name="save2" label="Close Case" />
        </div>
    </lightning:recordEditForm>
</div> </aura:component> 

这是控制器

({
handleLoad : function(component,event,helper) {
    console.log('handle handleLoad');
    component.set("v.showSpinner",false);
},handleSubmit : function(component,helper) {
    event.preventDefault(); // Prevent default submit
    var fields = event.getParam("fields");
    fields["Status"] = 'Hold';        
    component.find('recordEditor').submit(fields); // Submit form
    console.log('handle handleSubmit');
},handleSuccess : function(component,helper) {
    console.log('record updated successfully');
 *****<b>   //The below is returning the id of the Lighting:recordEditForm</b>***** 
    console.log(event.getsource().getLocalId());
    component.set("v.showSpinner",false);
    // Success! Prepare a toast UI message
    var resultsToast = $A.get("e.force:showToast");
    resultsToast.setParams({
        "title": "Case Saved","message": "The case has been closed"
    });
    resultsToast.fire();
    *****<b>//If statement required to check which button was pressed so the below only fires when lightning button with aura:id = 'button2' was pressed</b>*****
    var workspaceAPI = component.find("workspace");
    console.log('closing tab');
    workspaceAPI.getFocusedTabInfo().then(function(response) {
        var focusedTabId = response.tabId;
        workspaceAPI.closetab({tabId: focusedTabId});
    })
    .catch(function(error) {
        console.log(error);
    });
}})

我已在控制器中引用了单击按钮的控制器中用黑体标记了注释代码,并用星号标记了

任何帮助将不胜感激

q276941897 回答:获取在Lightning:recordEditForm的onsuccess属性中使用的lightning:button的ID

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3111947.html

大家都在问