我试图在$ A.createComponents的帮助下创建一个动态的闪电组件。
$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');
}
})
}
}
);
上面很好。而且,当用户单击中的“确定”按钮时,我想关闭组件 SubmitForApprovalFooter。
我在SubmitForApprovalFooter中使用了以下内容。
({
handleOK : function(cmp, event, helper) {
$A.get("e.force:closeQuickAction").fire();
}
})
但是什么也没发生,并且组件没有消失。 非常感谢您的帮助。
答案 0 :(得分:0)
所以我遇到了几次您遇到的相同问题。技巧是将模式承诺作为aura:attribute
保存在组件上。
c:SubmitForApprovalFooter
中,在类型为onClickAction
的名为Aura.Action
的组件上创建一个参数component.get("c.handleModalClose")
handleModalClose
函数中,获取模态Promise参数并从Promise中关闭模态。 (请参见下文)({
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();
});
}
})