Trailhead出现问题:“Get Hands-On with New Alert,Confirm和Prompt模块和组件”

3

我希望你能帮我翻译涉及IT技术的文本,这段需要翻译的内容是关于完成“使用新的警报、确认和提示模块和组件”挑战的问题。

我相信这个挑战存在一个错误,但我想知道是我犯了错还是该挑战有误。

任务要求:

import { LightningElement, api } from "lwc";
export default
class recordCardQuickFiles extends LightningElement {
 @api
 recordId;
 onDeleteAllFilesButtonClick() {
  const confirmation = confirm("Are you sure you want to delete all files?");
   if (confirmation) {
      //... proceed with
     //... Apex Logic to delete Files.
    //... We will not check this comment.
    }
  }
}
  • 创建新的Lightning Web组件
  • 名称:recordCardQuickFiles
  • 从"lightning/confirm"导入LightningConfirm
  • 使用LightningConfirm方法替换confirm方法
  • 消息:"您确定要删除所有文件吗?"
  • 变体:"headerless"
  • 标签:"您确定要删除所有文件吗?"

我的解决方案:

import { LightningElement, api } from "lwc";
import LightningConfirm from "lightning/confirm";
export default
class recordCardQuickFiles extends LightningElement {
    @api
    recordId;
    configs = {
        Message: "Are you sure you want to delete all files?",
        Label: "Are you sure you want to delete all files?",
        Variant: "headerless"
    }
    onDeleteAllFilesButtonClick() {
        const confirmation = LightningConfirm.open(this.configs);
        if (confirmation) {
            //... proceed with
            //... Apex Logic to delete Files.
            //... We will not check this comment.
        }
    }
}

出现错误:你的.org中的挑战尚未完成。 LightningConfirm方法中使用的消息不正确。


1
你是新来的。Stackoverflow是一个搜索信息、澄清疑问的手册。当你发布你的问题时,看起来好像你想让别人替你完成工作。这不太好。只是一个小建议,你认为有人会帮我解决我的专属问题吗? - Aloiso Junior
@AloisoJunior 你好,这不是我的工作任务。我需要完成这个挑战来继续JS认证。但我相信这个挑战有一个bug,我想知道是我犯了错误还是挑战本身有问题。 - Vladyslav Palamarchuk
1个回答

5
LWC的JS文件应该像以下这样:
import { LightningElement, api } from "lwc";
import LightningConfirm from 'lightning/confirm';

export default
class recordCardQuickFiles extends LightningElement {
    @api
    recordId;
    onDeleteAllFilesButtonClick() {
        const confirmation = LightningConfirm.open({
            Message: 'Are you sure you want to delete all files?',
            Variant: 'headerless',
            Label: 'Are you sure you want to delete all files?'
        });
        if (confirmation) {
            //... proceed with
            //... Apex Logic to delete Files.
            //... We will not check this comment.
        }
    }
}

我希望这有所帮助。谢谢!


谢谢,我在方法中使用了async await,它起作用了! - Vladyslav Palamarchuk
谢谢,这个方法可行。很烦人的是他们期望非常具体的代码。 - Raul

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接