SAPUI5使用XML文件作为具有“ data-sap-ui-resourceroots”的视图? [英] SAPUI5 Using XML-File as View with "data-sap-ui-resourceroots"?
问题描述
我正在执行SAPUI5演练,并停留在步骤4。(演练步骤4)
I'm doing the SAPUI5 Walkthrough and stuck at step 4. (Walkthrough Step 4)
我正在使用Eclipse,但不知道如何更改此代码行,因此它适用于我的项目,并且将找到我的看法。
I'm working with Eclipse and don't know how to change this code-line so it works for my project and is going to find my view.
data-sap-ui-resourceroots='{
"sap.ui.demo.wt": "./"
}'
我需要知道为 sap.ui.demo.wt。
I need to know what to insert for "sap.ui.demo.wt" when using an Eclipse project.
感谢任何提示:)
编辑:
现在我有了一个带有触发弹出式按钮的工作页。
Now I got a working page with a button which triggers a pop-up.
文件夹结构:
SAPUI5_Test
- WebContent
- controller
-> NewView.controller.js
- view
-> NewView.view.xml
- index.html
index.html:
index.html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta charset="UTF-8">
<title>SAPUI5 Walkthrough</title>
<script
id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async"
data-sap-ui-resourceroots='{
"SAPUI5_Test": "./"
}'>
</script>
<script>
sap.ui.getCore().attachInit(function () {
sap.ui.xmlview({
viewName: "SAPUI5_Test.view.NewView"
}).placeAt("content");
});
</script>
</head>
<body class="sapUiBody" id="content">
</body>
</html>
NewView.view.xml:
NewView.view.xml:
<mvc:View
controllerName="SAPUI5_Test.controller.NewView"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<Button
text="Say hello"
press="onShowHello"/>
</mvc:View>
NewView.controller.js
NewView.controller.js
sap.ui.controller("SAPUI5_Test.controller.NewView", {
onShowHello : function() {
alert("Hello SAPUI5_Controller");
}
});
非常感谢您的帮助!也许这可能对将来的人有所帮助:)
So thanks for the help! And maybe this could help someone in the future :)
推荐答案
SAPUI5正在按其资源搜索视图,控制器或其他类
SAPUI5 is searching for resources like views, controllers or other classes by their full names.
假设每个名称空间部分都是一个文件夹,并且类/视图名称是文件名。如果是视图,则文件名必须为xxx.view.xml。如果它是控制器,则文件名必须为xxx.controller.js。
It is assuming that every namespace part is a folder and the class/view name is the filename. If its a view the filename has to be xxx.view.xml. if its a controller the filename has to be xxx.controller.js.
默认情况下,开始搜索的根文件夹是sap-ui-core的文件夹.js。
The root folder where it starts its search is by default the folder of the sap-ui-core.js.
您可以通过定义data-sap-ui-resourceroots映射来更改根文件夹。它是一个将对象名称空间映射到路径(相对于index.html)的javascript对象。
You can change the root folder by defining a data-sap-ui-resourceroots mapping. Its a javascript object that maps a namespace to a path (relative to the index.html).
具有以下引导标记 company.myProject。在
/resources/company/myProject/view/View1.view.xml
:
<script id="sap-ui-bootstrap"
src="resources/sap-ui-core.js"></script>
使用此引导标记 company.myProject.View1
在 /view/View1.view.xml
中搜索:
With this bootstrap tag company.myProject.View1
is searched for at /view/View1.view.xml
:
<script id="sap-ui-bootstrap"
src="resources/sap-ui-core.js"
data-sap-ui-resourceroots='{
"company.myProject": "./" }'></script>
并使用此引导标记 company.myProject.View1 $ c $在
ddd / myProject / view / View1.view.xml
中搜索c>:
And with this bootstrap tag company.myProject.View1
is searched for at ddd/myProject/view/View1.view.xml
:
<script id="sap-ui-bootstrap"
src="resources/sap-ui-core.js"
data-sap-ui-resourceroots='{
"company": "./ddd" }'></script>
编辑:请注意,您必须使用
在地图内。'
将不起作用。
Please beware that you have to use "
inside of the map. '
will not work.
编辑:澄清文件夹结构
我建议您将所有内容都放在项目命名空间中,请使用以下文件夹结构:
I would recommend that you put everything in a project namespace. Use this folder structure:
WebContent
- controller
- NewView.controller.js
- view
- NewView.view.xml
- index.html
- 重命名 View 文件夹到 view (按惯例,命名空间为camelCase)。
- 将 newView.view.xml 重命名为 NewView.view.xml (类/视图按惯例是PascalCase)
- 使用
data-sap-ui-resourceroots ='{ myproject: ./} '
。 - 将您的控制器名称更改为 myproject.controller.NewView :
Controller.extend( myproject .controller.NewView,{...});
或sap.ui.controller( myproject.cont roller.NewView,{...});
。 - 在xmlview中使用
controllerName = myproject.controller.NewView
。 - 使用
sap.ui.xmlview({viewName: myproject.view.NewView})实例化视图。 内容);
。 - Rename View folder to view (namespaces are camelCase by convention).
- Rename newView.view.xml to NewView.view.xml (Classes/Views are PascalCase by convention)
- Use
data-sap-ui-resourceroots='{ "myproject": "./" }'
. - Change your Controller name to myproject.controller.NewView:
Controller.extend("myproject.controller.NewView", {...});
orsap.ui.controller("myproject.controller.NewView",{...});
. - In the xmlview use
controllerName="myproject.controller.NewView"
. - Instantiate the view with
sap.ui.xmlview({ viewName: "myproject.view.NewView"}).placeAt("content");
.
这样,您不必为项目中的每个子文件夹添加映射。
With that you don't have to add a mapping for every subfolder in your project.
这篇关于SAPUI5使用XML文件作为具有“ data-sap-ui-resourceroots”的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!