当前位置: 首页 > news >正文

SAP UI5 walkthrough step9 Component Configuration

在之前的章节中,我们已经介绍完了MVC的架构和实现,现在我们来讲一下,SAPUI5的结构

这一步,我们将所有的UI资产从index.html里面独立封装在一个组件里面

这样组件就变得独立,可复用了。这样,无所什么时候我们去访问资源的时候,我们都直接访问组件文件而不是index.html。这种方式使得我们的app变得更加灵活

文件拆分之后长这样

首先,我们先新建一个Component.js

webapp/Component.js (New)

sap.ui.define(["sap/ui/core/UIComponent"
], (UIComponent) => {"use strict";return UIComponent.extend("", {init() {// call the init function of the parentUIComponent.prototype.init.apply(this, arguments);}});
});
sap.ui.define(["sap/ui/core/UIComponent","sap/ui/model/json/JSONModel","sap/ui/model/resource/ResourceModel"
], (UIComponent, JSONModel, ResourceModel) => {"use strict";return UIComponent.extend("ui5.walkthrough.Component", {metadata : {"interfaces": ["sap.ui.core.IAsyncContentCreation"],"rootView": {"viewName": "ui5.walkthrough.view.App","type": "XML","id": "app"}},init() {// call the init function of the parentUIComponent.prototype.init.apply(this, arguments);// set data modelconst oData = {recipient : {name : "World"}};const oModel = new JSONModel(oData);this.setModel(oModel);// set i18n modelconst i18nModel = new ResourceModel({bundleName: "sap.ui.demo.walkthrough.i18n.i18n"});this.setModel(i18nModel, "i18n");}});
});

接下来,我们去修改App.controller.js

sap.ui.define(["sap/ui/core/mvc/Controller","sap/m/MessageToast"
], (Controller, MessageToast) => {"use strict";return Controller.extend("ui5.walkthrough.controller.App", {onShowHello() {// read msg from i18n modelconst oBundle = this.getView().getModel("i18n").getResourceBundle();const sRecipient = this.getView().getModel().getProperty("/recipient/name");const sMsg = oBundle.getText("helloMsg", [sRecipient]);// show messageMessageToast.show(sMsg);}});
});

修改index.js

webapp\index.js

sap.ui.define(["sap/ui/core/ComponentContainer"
], (ComponentContainer) => {"use strict";new ComponentContainer({name: "ui5.walkthrough",settings : {id : "walkthrough"},async: true}).placeAt("content");
});

Conventions

  • The component is named Component.js.

  • Together with all UI assets of the app, the component is located in the webapp folder.

  • The index.html file is located in the webapp folder if it is used productively.

最终实现效果还是和之前一样

http://www.lryc.cn/news/256136.html

相关文章:

  • 【数据结构和算法】--- 栈
  • CentOS7.0 下rpm安装MySQL5.5.60
  • 智慧能源:数字孪生压缩空气储能管控平台
  • 【链表OJ—反转链表】
  • TCP一对一聊天
  • 基于Java的招聘系统的设计与实现
  • spring boot整合mybatis进行部门管理管理的增删改查
  • 微软 Power Platform 零基础 Power Pages 网页搭建高阶实际案例实践(四)
  • 如何在任何STM32上面安装micro_ros
  • 肖sir__ 项目讲解__项目数据
  • 微服务实战系列之J2Cache
  • 12.ROS导航模块:gmapping、AMCL、map_server、move_base案例
  • C++中string类的使用
  • LeeCode每日刷题12.8
  • 硕士毕业论文格式修改要点_word
  • 远红外温和护理,一贴缓解痛风不适
  • 优化 SQL 日志记录的方法
  • Java设计模式-工厂模式
  • 每天五分钟计算机视觉:稠密连接网络(DenseNet)
  • mysql支持的整数类型、各类型整数能够表示的数值范围
  • 我不是DBA之慢SQL诊断方式
  • JavaScript基础知识整理(最全知识点, 精简版,0基础版)
  • 人工智能和网络安全:坏与好
  • 基于SSH的java记账管理系统
  • github可访问但无法clone问题
  • WebGL笔记:图形缩放的原理和实现
  • 前端学习--React(5)
  • 【数据结构】平衡树引入
  • 机器视觉相机镜头光源选型
  • Appium:iOS测试比Android测试更难?