zoukankan      html  css  js  c++  java
  • Step 17: Fragment Callbacks

    Step 17: Fragment Callbacks

    添加对话框的事件逻辑代码

    由于Fragment 不像view那样绑定controller,所以要想添加逻辑代码必须给它一个controller,也是就创建它的时候使用controller属性,this的含义是当前的controller。

    this.pDialog = Fragment.load({
    					id: oView.getId(),
    					name: "sap.ui.demo.walkthrough.view.HelloDialog",
    					controller: this
    				}).then(function (oDialog) {
    					// connect dialog to the root view of this component (models, lifecycle)
    					oView.addDependent(oDialog);
    					return oDialog;
    				});
    

    webapp/controller/HelloPanel.controller.js

    sap.ui.define([
    	"sap/ui/core/mvc/Controller",
    	"sap/m/MessageToast",
    	"sap/ui/core/Fragment"
    ], function (Controller, MessageToast, Fragment) {
    	"use strict";
    
    	return Controller.extend("sap.ui.demo.walkthrough.controller.HelloPanel", {
    
    		onShowHello : function () {
    			// read msg from i18n model
    			var oBundle = this.getView().getModel("i18n").getResourceBundle();
    			var sRecipient = this.getView().getModel().getProperty("/recipient/name");
    			var sMsg = oBundle.getText("helloMsg", [sRecipient]);
    
    			// show message
    			MessageToast.show(sMsg);
    		},
    
    		onOpenDialog : function () {
    			var oView = this.getView();
    
    			if (!this.pDialog) {
    				this.pDialog = Fragment.load({
    					id: oView.getId(),
    					name: "sap.ui.demo.walkthrough.view.HelloDialog",
    					controller: this
    				}).then(function (oDialog) {
    					// connect dialog to the root view of this component (models, lifecycle)
    					oView.addDependent(oDialog);
    					return oDialog;
    				});
    			} 
    			this.pDialog.then(function(oDialog) {
    				oDialog.open();
    			});
    		},
    
    		onCloseDialog : function () {
    			// note: We don't need to chain to the pDialog promise, since this event-handler
    			// is only called from within the loaded dialog itself.
    			this.byId("helloDialog").close();
    		}
    	});
    
    });
    

    把HelloPanel的controller给它用。
    注意controller属性的值不是必须是controller,可以是任何object

    this.byId("helloDialog")是得到对话框对象,
    注意:这里不需要使用promise,因为调用它的时候,对话框肯定已经被加载完毕了。

    webapp/view/HelloDialog.fragment.xml

    <core:FragmentDefinition
       xmlns="sap.m"
       xmlns:core="sap.ui.core" >
       <Dialog
          id="helloDialog"
          title ="Hello {/recipient/name}">
          <beginButton>
             <Button
                text="{i18n>dialogCloseButtonText}"
                press=".onCloseDialog"/>
          </beginButton>
       </Dialog>
    </core:FragmentDefinition>
    

    在fragment里加一个beginButton(也有与之对应的endButton),当按钮被按下后,调用 HelloPanel controller的onCloseDialog方法。

    webapp/i18n/i18n.properties

    # App Descriptor
    appTitle=Hello World
    appDescription=A simple walkthrough app that explains the most important concepts of SAPUI5
    
    # Hello Panel
    showHelloButtonText=Say Hello
    helloMsg=Hello {0}
    homePageTitle=Walkthrough
    helloPanelTitle=Hello World
    openDialogButtonText=Say Hello With Dialog
    dialogCloseButtonText=Ok
    

    vx:xiaoshitou5854

  • 相关阅读:
    算法与数据结构 (四) 排序 一 交换类排序
    算法与数据结构 (三) 二叉树的简单应用 二叉查找树,二叉堆排序
    算法与数据结构 (二) 二叉树的简单实现,非递归的前序遍历 中序遍历 后序遍历
    算法与数据结构 (一) 链表,栈,队列的简单实现
    服务器端的redis和MySQL的远程连接的简单解决方案
    记一次自定义监听器使用spring 管理的bean的问题
    基于java开发的RBAC模型权限管理系统
    2019 本科java开发春招面经(实习)
    记一次Bootstrap框架下 使用Ajax失效的问题
    [转]在static代码块或static变量的初始化过程中使用ServiceManager提供的api的陷阱
  • 原文地址:https://www.cnblogs.com/xiaoshiwang/p/15194483.html
Copyright © 2011-2022 走看看