![](/img/trans.png)
[英]Not able to call apex controller from lightning component's helper class
[英]Not being able to close the dynamic lightning component
我試圖在 $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();
}
})
但是什么也沒有發生,組件也不會消失。 任何幫助深表感謝。
所以我遇到過你幾次相同的問題。 訣竅是將模態承諾保存為aura:attribute
組件上。
c:SubmitForApprovalFooter
,在名為onClickAction
的組件上創建一個onClickAction
類型的Aura.Action
component.get("c.handleModalClose")
handleModalClose
函數中,獲取modal promise 參數並從promise 中關閉modal。 (見下文)({
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();
});
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.