SAPUI5 / Fiori Elements:在使用未在控制器文件中触发的片段创建的对话框中按下按钮

问题描述 投票:0回答:1

我正在按照使用 RAP 进行 Excel 上传来开发我的第一个 fiori 应用程序:第 -3 部分 | SAP 博客

由于博客现在有点旧,我必须编辑博客中的一些内容才能使其正常工作。

现在,我可以看到上传对话框,但上面的按钮不起作用。

File structure

Snippet from the manifest file

Code snippet in the controller for one of the buttons

Fragment used

Output

虽然顶部的上传按钮可以工作,但底部的 3 个从片段中添加的按钮都不起作用。

我尝试在片段中进行更改

<Button id="Template" text="Template" press="onTempDownload" icon="sap-icon://download-from-cloud" type="Emphasized"/><br>

<Button id="Template" text="Template" press=".onTempDownload" icon="sap-icon://download-from-cloud" type="Emphasized"/><br>
by adding a dot so it refers to the controller

以及

<Button id="Template" core:require="{ handler: '/home/user/projects/ypgms_building_v2/webapp/ext/controller/ListReportExt'}" text="Template" press="handler.onTempDownload" icon="sap-icon://download-from-cloud" type="Emphasized"/>

但是第二次更正给了我一个错误,即该路径不在资源下。我不知道如何让 /ext 文件夹显示在 F12 开发人员选项的资源部分下。

最终,按钮应该触发控制器中相应的功能,如片段中的按下事件中所述,但这没有发生。

正确的做法是什么?

谢谢

javascript sapui5 sap-fiori ui5-tooling abap-adt
1个回答
0
投票

正如之前提到的,您的代码有点混乱,但是我附加了我通常用来打开对话框的通用函数。然后,对话框和从其中调用的函数可以由视图的控制器处理。

  onOpenDialog(oEvent, sDialogId, oDialogPath) {
    return new Promise((resolve) => {
      if (!this.getView().byId(sDialogId)) {
        Fragment.load({
          id: this.getView().getId(),
          name: oDialogPath,
          controller: this,
        }).then(
          function (oDialog) {
            this.getView().addDependent(oDialog);
            oDialog.addStyleClass(this.getOwnerComponent().getContentDensityClass());
            oDialog.open();
            resolve();
          }.bind(this)
        );
      } else {
        this.getView().byId(sDialogId).open();
        resolve();
      }
    });
  },
© www.soinside.com 2019 - 2024. All rights reserved.