Salesforce 无法关闭动态lightning组件

Salesforce 无法关闭动态lightning组件,salesforce,salesforce-lightning,Salesforce,Salesforce Lightning,我正试图在$a.createComponents的帮助下创建一个动态lightning组件 $A.createComponents([ ["c:SubmitForApprovalBody",{oppId:recordId}], [ "c:SubmitForApprovalFooter", { okLabel : "Confirm"}] ], function(components, status){

我正试图在$a.createComponents的帮助下创建一个动态lightning组件

 $A.createComponents([
         ["c:SubmitForApprovalBody",{oppId:recordId}],
         [ "c:SubmitForApprovalFooter", { okLabel : "Confirm"}]            

       ],
       function(components, status){
           console.log('status : '+status);
           if (status === "SUCCESS") {
               modalBody = components[0];
               modalFooter = components[1];                 
               component.find('modalLib').showCustomModal({
                   header: "Submit for Approval",
                   body: modalBody,
                   footer:modalFooter,
                   showCloseButton: false,
                   closeCallback: function() {
                      alert('you decided to close');
                   }
               })
           }
       }
    );
以上是好的。并且,我想在用户单击中的ok按钮时关闭组件 提交批准书

我在SubmitForApprovalFooter中使用了下面的一个

 ({
     handleOK : function(cmp, event, helper) {
        $A.get("e.force:closeQuickAction").fire();
     }
  })
但是什么也没有发生,组件也没有消失。
非常感谢您的帮助。

因此,我曾多次遇到过与您相同的问题。诀窍是将模式承诺保存为组件上的
aura:attribute

  • 在组件
    c:SubmitForApprovalFooter
    中,在类型为
    Aura.Action
    的组件
    onClickAction
    上创建一个参数
  • 在js中将该属性设置为
    component.get(“c.handleModelClose”)
  • handleModelClose
    函数中,获取模态承诺参数并从承诺中关闭模态。(见下文)
  • ({
    yourAction:函数(组件、事件、助手){
    $A.createComponents([
    [“c:SubmitForApprovalBody”{oppId:recordId}],
    //注意设置了'onclickAction'
    //如果您遇到此问题,请使用component.getReference(“c.handleModelClose”)
    [“c:SubmitForApprovalFooter”{okLabel:“确认”,
    “onclickAction”:component.get(“c.HandleModelClose”)
    }]
    ],
    功能(组件、状态){
    console.log('状态:'+状态);
    如果(状态==“成功”){
    modalBody=组件[0];
    modalFooter=组件[1];
    //设置包含承诺的变量
    var modalPromise=component.find('modalLib')。showCustomModal({
    标题:“提交审批”,
    正文:modalBody,
    页脚:modalFooter,
    showCloseButton:false,
    closeCallback:function(){
    警报(“您决定关闭”);
    }
    })
    //将modalPromise设置为组件的属性,类型为“Object”`
    //所以``
    组件集(“v.modalPromise”,modalPromise);
    }
    }
    );
    },
    HandleModelClose:函数(组件、事件、帮助器){
    //我现在一直在使用这个,否则aura可能会试图
    //抓住一个已经被破坏的模式承诺
    event.stopPropagation();
    var modPromise=component.get(“v.modalPromise”);
    modPromise.then(函数(m){
    m、 close();
    });
    }
    })
    
    ({
        yourAction : function(component, event, helper) {
            $A.createComponents([
                ["c:SubmitForApprovalBody",{oppId:recordId}],
                //Notice the `onclickAction` being set
                //If you experience issues with this then use component.getReference("c.handleModalClose")
                [ "c:SubmitForApprovalFooter", { okLabel : "Confirm",
                                                "onclickAction":component.get("c.handleModalClose")
                                            }]
              ],
              function(components, status){
                  console.log('status : '+status);
                  if (status === "SUCCESS") {
                      modalBody = components[0];
                      modalFooter = components[1];
                      //Set a variable containing the promise                 
                        var modalPromise = component.find('modalLib').showCustomModal({
                          header: "Submit for Approval",
                          body: modalBody,
                          footer:modalFooter,
                          showCloseButton: false,
                          closeCallback: function() {
                             alert('you decided to close');
                          }
                      })
                      //Set the modalPromise as an attribute on your component, type is `Object`
                      //So, `<aura:attribute name="modalPromise" type="Object"/>`
                      component.set("v.modalPromise",modalPromise);
                  }
              }
           );
        },
        handleModalClose : function(component,event,helper){
            //I use this all the time now, otherwise aura may try to 
            //grab a modal promise that has been destroyed already
            event.stopPropagation();
            var modPromise = component.get("v.modalPromise");
            modPromise.then(function(m){
                m.close();
    
            });
        }
    })