由于错误 "Cannot instantiate object: 'new' is missing!",片段无法打开

Fragment won't open due to the error "Cannot instantiate object: 'new' is missing!"

很遗憾,我的片段页面打不开。 尝试在按下按钮后打开 select 对话框(带有 table 的片段)。

这里是 error:

formatter function sap.f.FlexibleColumnLayoutWithOneColumnStart.controller.Formatter not found!


Uncaught (in promise) Error: Cannot instantiate object: "new" is missing!
    at constructor (Object-dbg.js:39:11)
    at constructor (EventProvider-dbg.js:29:14)
    at constructor (ManagedObject-dbg.js:464:17)
    at constructor (Fragment-dbg.js:122:17)
    at f._configDialog (DetailDetail.controller.js?eval:120:4)
    at f.eval (DetailDetail.controller.js?eval:84:10)

我的项目文件夹中有一个 Formatter。 属性_pDialog好像是空的,虽然我的观点明明是存在的

错误在方法handleTableSelectDialogPress

sap.ui.define([
    "sap/ui/model/json/JSONModel",
    "sap/ui/core/mvc/Controller",
    "sap/ui/core/Fragment",
    "sap/m/MessageToast",
    "./Formatter",
    "sap/ui/core/Fragment",
    "sap/ui/model/Filter",
    "sap/ui/model/FilterOperator",
    "sap/ui/model/json/JSONModel",
    "sap/ui/core/syncStyleClass",
], function(JSONModel, Controller, Fragment, MessageToast, FilterOperator, syncStyleClass) {
    "use strict";

    return Controller.extend("sap.f.FlexibleColumnLayoutWithOneColumnStart.controller.DetailDetail", {
        // ...,

        handleTableSelectDialogPress: function(oEvent) {
            var oButton = oEvent.getSource(),
                oView = this.getView();
            if (!this._pDialog) {
                this._pDialog = Fragment.load({
                    id: oView.getId(),
                    name: "sap.f.FlexibleColumnLayoutWithOneColumnStart.view.Dialog",
                    controller: this
                }).then(function(oDialog) {
                    oView.addDependent(oDialog);
                    return oDialog;
                });
            }

            this._pDialog.then(function(oDialog) {
                this._configDialog(oButton, oDialog);
                oDialog.open();
            }.bind(this));
        },

        _configDialog: function(oButton, oDialog) {
            // ...
            syncStyleClass("sapUiSizeCompact", this.getView(), oDialog);
        },

        // ...
    });
});

这是我的观点:

<mvc:View displayBlock="true" controllerName="sap.f.FlexibleColumnLayoutWithOneColumnStart.controller.DetailDetail" height="100%" xmlns:mvc="sap.ui.core.mvc"   xmlns="sap.f" xmlns:m="sap.m">
    <DynamicPage toggleHeaderOnTitleClick="false">
        <!-- ... -->
        <content>
            <m:Button
                class="sapUiSmallMarginBottom"
                text="Show Table Select Dialog"
                press=".handleTableSelectDialogPress"
                ariaHasPopup="Dialog" />
        </content>
    </DynamicPage>
</mvc:View>

这是我的片段:

<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns="sap.m">
    <TableSelectDialog id="myDialog"
        title="Select Product"
        search=".handleSearch"
        confirm=".handleClose"
        cancel=".handleClose"
        items="{
            path: '/ProductCollection',
            sorter: {
                path: 'Name',
                descending: false
            }
        }">
        <ColumnListItem vAlign="Middle">
            <!-- ... -->
        </ColumnListItem>
        <columns>
            <!-- ... -->
        </columns>
    </TableSelectDialog>
</core:FragmentDefinition>

这是我的项目文件夹:

控制器工厂函数的回调参数数组中所需的依赖项不匹配

sap.ui.define([
  "sap/ui/model/json/JSONModel",
  "sap/ui/core/mvc/Controller",
  "sap/ui/core/Fragment",
  "sap/m/MessageToast",
  "./Formatter", // <-- here you required Formatter
  "sap/ui/core/Fragment", // <-- required Fragment (again)
  "sap/ui/model/Filter",
  "sap/ui/model/FilterOperator",
  "sap/ui/model/json/JSONModel", // <-- required JSONModel (again)
  "sap/ui/core/syncStyleClass",
], /*factory*/function(JSONModel, Controller, Fragment, MessageToast, <del>FilterOperator</del>/*<-- Formatter */, <del>syncStyleClass</del>/*<-- Fragment */) {/* ... */});

因此,参数syncStyleClass不是模块sap/ui/core/syncStyleClass而是sap/ui/core/Fragment调用 Fragment() 而没有 new 结果是 error "new" is missing!.

函数参数名称与框架无关。重要的是这些参数根据依赖项列表的正确顺序。来自 API reference of sap.ui.define:

The module export of each dependency module will be provided as a parameter to a factory function, the order of the parameters will match the order of the modules in the dependencies array.

同样的规则适用于sap.ui.require