So we determine what is in the sap core:
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/routing/History",
"sap/ui/model/json/JSONModel"
], function (Controller,History,JSONModel)
My sap app id: "sap.ui.test
".
So I want to connect the controller to one that already exists:
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/routing/History",
"sap/ui/model/json/JSONModel",
"sap/ui/test/webapp/controller/TopMenu"
], function (Controller,History,JSONModel,TopMenu)
And I get an error: Error: failed to load 'sap/ui/test/webapp/controller/TopMenu.js
. Although the road looks like right. Project structure attached in the screenshot.
I can not understand whether it is possible to identify the controller in such a way?
You would have to use
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/routing/History",
"sap/ui/model/json/JSONModel",
"sap/ui/test/controller/TopMenu.controller"
], function (Controller,History,JSONModel,TopMenu)
That's because of the old controller naming convention: Your controllers have to be named ABC.controller.js
. The sap.ui.define
function searches for files and is not aware of this convention. It does not know that you would like to load a controller this time.
try
sap.ui.define([ "sap/ui/core/mvc/Controller", "sap/ui/core/routing/History", "sap/ui/model/json/JSONModel", "sap/ui/test/controller/TopMenu" ], function (Controller,History,JSONModel,TopMenu)
You do not need to tell your app the exact path, you did this already within you Index.html
(something like data-sap-ui-resourceroots='{"sap.ui.test": "sap/ui/test/webapp"}'>
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.