在salesforce中我们经常需要用到Pop up window的功能, 现在把代码整理如下:
在HTML文件中的具体实现:
<!-- Show Confirm Dialog-->
<template if:true={isShowConfirmModal}>
<section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true"
aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
<div class="slds-modal__container">
<header class="slds-modal__header slds-theme_alert-texture slds-theme_error">
<button class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse"
title="Close" onclick={handleCloseModal}>
<lightning-icon icon-name="utility:close" alternative-text="close" variant="inverse">
</lightning-icon>
</button>
<h2 id="modal-heading-01" class="slds-modal__title slds-hyphenate">Warning</h2>
</header>
<div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
<p>
You are about to associate a lead to an existing company that already has a corporate administrator. Please speak to the corporate administrator.
</p>
<p>
Do you still wish to associate this lead to the company?
</p>
</div>
<footer class="slds-modal__footer slds-modal__footer_directional">
<button class="slds-button slds-button_neutral" onclick={handleCloseModal}>No</button>
<button class="slds-button slds-button_brand" onclick={handleContinue}>Yes</button>
</footer>
</div>
</section>
<div class="slds-backdrop slds-backdrop_open"></div>
</template>
在JS里面的处理是:
handleCloseModal(){
this.isShowConfirmModal = false;
}
handleContinue(){
// do some logic here
}
之前有遇到一个问题就是 Pop up的 window 的message是在Custom Setting里面设置的,所以返回值需要返回值需要分段显示:例如在Custom Setting里面的设置是:AAAAAA BBBBB
这个时候需要在前端处理一下,具体操作是:
getAcknowledgedText(){
let r = /\r\n|[\r\n]/;
getReviewAndSubmitText({'recordId' : this.asseId}).then(res=>{
if(res){
let str = res.split(r)
if(str.length > 0){
for(let i = 0 ; i< str.length ; i++){
// this.AcknowledgedText.push(str[i]);
if(i === 0){
this.AcknowledgedTextTitle = str[0];
}else{
this.AcknowledgedText.push(str[i]);
}
}
}
}
})
}
网友评论