简体   繁体   English

如何在SAP UI中的控制器中定义自定义控制器?

[英]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.

相关问题 如何在控制器(SAP UI5)中设置div的可见性 - how to set visibility of div in controller (SAP UI5) 我有一个由itemid定义的组件,该如何在控制器中获取它 - I have a component define by itemid how I can get it in controller 使用“ controller as”语法时,如何访问控制器中的“ this”? - How can I access the “this” in my controller when using “the controller as” syntax? 如何在来自另一个文件的控制器中定义变量? - How can I define a variable in a controller who is from another file? 如何在控制器中测试功能? - how can I test functions in my controller? 如何使ui-router控制器正常工作? - How can I make ui-router controller to work? 我正在使用 angular ui-select 进行下拉。 如何在我的控制器中获取选定的值? - I am using angular ui-select for drop down. How can I get the selected value in my controller? 如何使用ui-router在组件驱动的体系结构中定义控制器? - How to define a controller in Component Driven Architecture using ui-router? 如何在角度UI模式控制器中定义函数 - How to define a function inside angular ui modal controller 如何按SAP UI5中可以为空的属性对列表进行分组? - How do I group my list by an attribute which can be null in SAP UI5?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM