[英]How i can define custom controller in my controller in sap ui?
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
". 我的SAP应用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
. 我得到一个错误: 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
. 那是因为旧的控制器命名约定:您的控制器必须命名为ABC.controller.js
。 The sap.ui.define
function searches for files and is not aware of this convention. sap.ui.define
函数搜索文件,并且不了解此约定。 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 您无需告诉您的应用确切路径,您已经在Index.html中完成了此操作
(something like data-sap-ui-resourceroots='{"sap.ui.test": "sap/ui/test/webapp"}'>
) (类似于data-sap-ui-resourceroots='{"sap.ui.test": "sap/ui/test/webapp"}'>
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.