无法关闭动态闪电组件
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');
}
})
}
}
);
以上就可以了。而且,我想在用户点击 ok 按钮时关闭组件
提交批准页脚。
我在 SubmitForApprovalFooter 中使用了下面的。
({
handleOK : function(cmp, event, helper) {
$A.get("e.force:closeQuickAction").fire();
}
})
但是没有任何反应,组件也没有消失。
非常感谢任何帮助。
所以我遇到过几次与您相同的问题。诀窍是将模态承诺保存为组件上的 aura:attribute
。
- 在您的组件
c:SubmitForApprovalFooter
中,在名为 onClickAction
的组件上创建类型为 Aura.Action
的参数
- 在您的 js 中将该属性设置为
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();
});
}
})
我正在尝试在 $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');
}
})
}
}
);
以上就可以了。而且,我想在用户点击 ok 按钮时关闭组件 提交批准页脚。
我在 SubmitForApprovalFooter 中使用了下面的。
({
handleOK : function(cmp, event, helper) {
$A.get("e.force:closeQuickAction").fire();
}
})
但是没有任何反应,组件也没有消失。 非常感谢任何帮助。
所以我遇到过几次与您相同的问题。诀窍是将模态承诺保存为组件上的 aura:attribute
。
- 在您的组件
c:SubmitForApprovalFooter
中,在名为onClickAction
的组件上创建类型为Aura.Action
的参数
- 在您的 js 中将该属性设置为
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();
});
}
})