Fiori学习专题十五:Nested Views

Nested Views也就是嵌套页面,有时候我们同一个页面会用在多处,为了不重复构造页面,可以把这个页面剥离出来。

1.view文件夹下新建一个页面HelloPanel.view.xml

复制代码
<mvc:View
   controllerName="ui5.walkthrough.controller.HelloPanel"
   xmlns="sap.m"
   xmlns:mvc="sap.ui.core.mvc">
   <Panel
      headerText="{i18n>helloPanelTitle}"
      class="sapUiResponsiveMargin"
      width="auto">
      <content>
         <Button
            text="{i18n>showHelloButtonText}"
            press=".onShowHello"
            class="myCustomButton"/>
         <Input
            value="{/recipient/name}"
            valueLiveUpdate="true"
            width="60%"/>
         <FormattedText
            htmlText="Hello {/recipient/name}"
            class="sapUiSmallMargin sapThemeHighlight-asColor myCustomText"/>
      </content>
   </Panel>
</mvc:View>

2.新建controller,webapp/controller/HelloPanel.controller.js

复制代码
sap.ui.define([
   "sap/ui/core/mvc/Controller",
   "sap/m/MessageToast"
], (Controller, MessageToast) => {
   "use strict";

   return Controller.extend("ui5.walkthrough.controller.HelloPanel", {
      onShowHello() {
         // read msg from i18n model
         const oBundle = this.getView().getModel("i18n").getResourceBundle();
         const sRecipient = this.getView().getModel().getProperty("/recipient/name");
         const sMsg = oBundle.getText("helloMsg", [sRecipient]);

         // show message
         MessageToast.show(sMsg);
      }
   });
});

3.改造App.view.xml 以及 App.controller.js

复制代码
<mvc:View
	controllerName="ui5.walkthrough.controller.App"
	xmlns="sap.m"
	xmlns:mvc="sap.ui.core.mvc"
	displayBlock="true">
	<Shell>
		<App class="myAppDemoWT">
			<pages>
				<Page title="{i18n>homePageTitle}">
					<content>
						<mvc:XMLView viewName="ui5.walkthrough.view.HelloPanel"/>
					</content>
				</Page>
			</pages>
		</App>
	</Shell>
</mvc:View>

sap.ui.define([
   "sap/ui/core/mvc/Controller"
], (Controller) => {
   "use strict";

   return Controller.extend("ui5.walkthrough.controller.App", {
   });
});

这里其实我们就是把Panel控件的内容抽出来放在一个新的页面上,再通过<mvc:XMLView viewName="ui5.walkthrough.view.HelloPanel"/>,放在App.view。同时对于新的页面,需要创建新的controller。

相关推荐
广州智造9 分钟前
Radioss复合材料使用的单元属性
前端·设计·cad·建模·cae·radioss
我命由我1234535 分钟前
Photoshop - 将Photoshop图像置入其他应用程序
学习·ui·职场和发展·求职招聘·职场发展·学习方法·photoshop
张宏宇36 分钟前
我把微软开源的 tgrep 做成了本地版 GitHub Code Search:45,629 个文件里搜一次 10ms
前端·后端
huakoh43 分钟前
MCP 调用超时后别急着重试:三步读回分清执行状态
前端
打工仔折腾 AI43 分钟前
把模型切换交给平台:用蓝耘智能路由搭建商品评论分析工具
java·服务器·前端·后端·python·性能优化·ai agent 实战
个 人 练 习 生44 分钟前
C++-----string基本使用详解
开发语言·c++·学习
不可能片场1 小时前
Electron 发布标题的冒号 击穿命令行解析
前端·electron
reeswell1 小时前
我开源了 inspect-devtools —— 让 AI 终于能"看见"你屏幕上的组件
前端·人工智能
千谦阙听1 小时前
【C++篇】:string类——常用接口、底层原理与深浅拷贝
开发语言·c++·学习·visual studio
Yuhano1 小时前
W3. 实现Agent工具调用引擎
前端·aigc·ai编程