Walkthrough-Step15 Nested Views

页面的复用,这节主要是把之前页面中的panel分离出来单独做一个view,它有自己单独的处理逻辑,这样就可以方便了view的复用

webapp/view/App.view.xml

<mvc:View
	controllerName="sap.ui.demo.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="sap.ui.demo.walkthrough.view.HelloPanel"/>
					</content>
				</Page>
			</pages>
		</App>
	</Shell>
</mvc:View>

将之前页面page下的整个panel控件,包括它的子控件拿掉,写一个XMLView在这里<mvc:XMLView viewName="Step15_NestedView.view.HelloPanel"/>注意命名空间是mvc:

webapp/view/HelloPanel.view.xml
新建 一个xmlview HelloPanel.view.xml
Step15NestedViewcreatenew
向导创建完要把<app><pages><page>这些节点删除,然后把之前App View中的Panel的内容完全copy过来

<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" controllerName="Step15_NestedView.controller.HelloPanel"
	xmlns:html="http://www.w3.org/1999/xhtml">
	<Panel headerText="{i18n>panelTitle}" class="sapUiResponsiveMargin" width="auto">
		<content>
			<Button text="ClickMe" width="100px" class="myCustomButton" id="__button0" press="onClickMe"/>
			<Input width="200px" id="__input0" value="{aaa>/recipient/name}" description="Hello {aaa>/recipient/name}" valueLiveUpdate="true"/>
			<Text id="__text0" text="{i18n>newText}" class="sapUiSmallMargin sapThemeHighlight-asColor myCustomText"/>
		</content>
	</Panel>
</mvc:View>

webapp/controller/HelloPanel.controller.js
同时也要把App controller中的按钮点击事件剪切过来:

sap.ui.define([
	"sap/ui/core/mvc/Controller", "sap/m/MessageToast"
], function(Controller, MessageToast) {
	"use strict";
	return Controller.extend("Step15_NestedView.controller.HelloPanel", {
		onClickMe: function(oEvent) {
			//read from i18n Model
			var oBundle = this.getView().getModel("i18n").getResourceBundle();
			var sRecipient = this.getView().getModel("aaa").getProperty("/recipient/name");
			//var sMsg = oBundle.getText("helloMsg", [sRecipient]);
			var aStr = "bbbb";
			var sMsg1 = oBundle.getText("newText", [sRecipient, aStr]);
			MessageToast.show(sMsg1);
			//This code was generated by the layout editor.
			//MessageToast.show("you Clicked me!");
		}
	});
});

执行效果是一样的

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值