TypeError Controller.Extend不是一个函数



运行我的项目时,我会得到:

错误:从.//controller/plant.controller.js:typeError:typeError:controller.extend.extend不是函数

请让我知道如何修复它。

plant.controller.js

sap.ui.define([
    "sap/ui/core/mvc/Controller",
    "jquery.sap.global",
    "stock/Formatter",
    "sap/ui/core/routing/History",
    "sap/ui/model/json/JSONModel"
], function (jQuery, Formatter, Controller, History, JSONModel) {
    "use strict";
    var TableController =  Controller.extend("stock.controller.plant", {
        onInit: function () {
            var oModel = new JSONModel(jQuery.sap.getModulePath("sap.ui.demo.mock", "/products.json"));
            this.getView().setModel(oModel);
        },
        getRouter : function () {
            return sap.ui.core.UIComponent.getRouterFor(this);
        },
        onNavBack: function (oEvent) {
            var oHistory = History.getInstance();
            var sPreviousHash = oHistory.getPreviousHash();
            if (sPreviousHash !== undefined) {
                window.history.go(-1);
            } else {
                this.getRouter().navTo("input", {}, true /*no history*/);
            }
        }
    });
    return TableController;
});

component.js

sap.ui.define([
    "sap/ui/core/UIComponent",
    "sap/ui/core/mvc/XMLView",
    "sap/ui/model/json/JSONModel"
], function(UIComponent, JSONModel, XMLView) {
    "use strict";
    var Component = UIComponent.extend("stock.Component", {
        metadata: {
            manifest: "json",
            getTable: function () {
                return this._rootView.getContent()[0];
            }
        },
        publicMethods: [
            "getTable"
        ],
        dependencies: {
            libs: [
                "sap.m",
                "sap.ui.layout"
            ]
        },
        rootView: "stock.view.input",
        config: {
            sample: {
                files: [
                    "view.input.view.xml",
                    "controller.main.controller.js",
                    "Formatter.js"
                ],
                description : "In this example assisted input is provided with table-like suggestions where several columns can display more details."
            }
        },
        init : function () {
            UIComponent.prototype.init.apply(this, arguments);
            this.getRouter().initialize();
        }
    });
    Component.prototype.createContent = function () {
        this._rootView = sap.ui.xmlview({ viewName : "stock.view.plant" });
        return this._rootView;
    };
    return Component;
});

您忽略了文件声明的顺序。在您的示例中,您将"库存/格式化"文件用作"控制器",这显然是错误的。以下是正确的序列:

sap.ui.define([
        'sap/ui/core/mvc/Controller',
        'jquery.sap.global',
        'stock/Formatter',
        'sap/ui/core/routing/History',
        'sap/ui/model/json/JSONModel'
    ], function (Controller, jQuery, Formatter, History,JSONModel) {
});

最新更新