您可以为 SAP Fiori 应用程序创建可重用的库项目。将您的 BaseController 放入该库中。然后在您的应用程序项目中导入该库并从 BaseController 扩展您的应用程序控制器。
在基础项目的根文件夹中定义 library.js
sap.ui.define(["jquery.sap.global",
"sap/ui/core/library"], // library dependency
function(jQuery) {
"use strict";
// delegate further initialization of this library to the Core
sap.ui.getCore().initLibrary({
name: "mylibrary.reuse",
version: "1.0",
dependencies: ["sap.ui.core"],
types: [],
interfaces: [],
controls: [],
elements: [],
noLibraryCSS: true
});
return mylibrary.reuse;
}, /* bExport= */ true);
在它的 JS 文件中声明 BaseController
jQuery.sap.declare("mylibrary.reuse.BaseController");
/** Controller Definition **/
在 neo-app.json 中定义和公开库的入口点
{
"routes": [{
"path": "/resources/mylibrary/reuse",
"target": {
"type": "application",
"name": "myreuselibrary",
"entryPath": "/mylibrary/reuse"
},
"description": "SAPUI5 Resources"
},
}
然后在应用项目中导入上面的库,做JQuery.require()得到BaseController,然后扩展它。
我希望这会有所帮助。