简体   繁体   English

以闪电般的快速动作捕获 X 关闭按钮事件

[英]Capture X close button event in lightning quick action

I have one quick action which opens up the aura lightning component.我有一个快速动作可以打开光环闪电组件。 In that I have one requirement to execute some logic when the quick action is closed by "X" close button on the top right corner( not by cancel button ).因为我有一个要求,当快速操作被右上角的“X”关闭按钮(而不是取消按钮)关闭时,我需要执行一些逻辑。

在此处输入图像描述

I was searching so many articles most of them explained about closing the quick action by clicking the cancel button.我搜索了很多文章,其中大多数都解释了通过单击取消按钮来关闭快速操作。 I would like to know whether we can write some logic when quick action is closed by "X" close button or is there any way we can capture the onClick event for this close button.我想知道当快速操作被“X”关闭按钮关闭时我们是否可以编写一些逻辑,或者有什么方法可以捕获这个关闭按钮的 onClick 事件。

I couldn't share any code snippets because I have not written any, still I am searching for solutions.我无法分享任何代码片段,因为我没有编写任何代码片段,但我仍在寻找解决方案。

Have you seen the aura component lifecycle , especially stuff around (re)rendering the component?你见过光环组件生命周期,尤其是围绕(重新)渲染组件的东西吗? You could attach what you need to "unrender" call .您可以附加“取消渲染”调用所需的内容。

Put this in myComponent/myComponentRenderer.js and try?把它放在myComponent/myComponentRenderer.js中试试?

({
    unrender: function () {
        this.superUnrender();
        alert('You\'re closing me, I thought we were friends');
    }
})

在此处输入图像描述

Alternatively have a look at handling aura:valueDestroy .或者看看处理aura:valueDestroy I mean renderer should just try to clean some custom DOM stuff, free memory maybe, shouldn't run business logic.我的意思是渲染器应该尝试清理一些自定义 DOM 的东西,也许是免费的 memory,不应该运行业务逻辑。 If there's a more appropriate system event - maybe play with that one?如果有更合适的系统事件- 也许玩那个?

Have you tried creating a custom event to handle this?您是否尝试过创建自定义事件来处理此问题?
Reference: Lightning Aura Components Developer Guide: Create Custom Component Events 参考:Lightning Aura 组件开发人员指南:创建自定义组件事件

Create a custom component event using the <aura:event> tag in a.evt resource.使用 a.evt 资源中的<aura:event>标记创建自定义组件事件。 Events can contain attributes that can be set before the event is fired and read when the event is handled.事件可以包含可以在事件触发之前设置并在事件处理时读取的属性。 Use type="COMPONENT" in the <aura:event> tag for a component event.<aura:event>标记中为组件事件使用type="COMPONENT" For example, this c:compEvent component event has one attribute with a name of message .例如,这个 c:compEvent 组件事件有一个名为message的属性。

    1.  <!--c:compEvent-->
    2.  <aura:event type="COMPONENT">
    3.      <!-- Add aura:attribute tags to define event shape.
    4.           One sample attribute here. -->
    5.      <aura:attribute name="message" type="String"/>
    6.  </aura:event>
    7.

The component that fires an event can set the event's data.触发事件的组件可以设置事件的数据。 To set the attribute values, call event.setParam() or event.setParams() .要设置属性值,请调用event.setParam()event.setParams() A parameter name set in the event must match the name attribute of an <aura:attribute> in the event.事件中设置的参数名称必须与事件中<aura:attribute>name属性匹配。 For example, if you fire c:compEvent , you could use:例如,如果您触发c:compEvent ,您可以使用:

    1.
    2. event.setParam("message", "event message here");
    3.

The component that handles an event can retrieve the event data.处理事件的组件可以检索事件数据。 To retrieve the attribute value in this event, call event.getParam("message") in the handler's client-side controller.要检索此事件中的属性值,请在处理程序的客户端 controller 中调用event.getParam("message")

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM