SAP UI5 walkthrough step9 Component Configuration

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

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

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

文件拆分之后长这样

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

webapp/Component.js (New)

javascript 复制代码
sap.ui.define([
   "sap/ui/core/UIComponent"
], (UIComponent) => {
   "use strict";

   return UIComponent.extend("", {
      init() {
         // call the init function of the parent
         UIComponent.prototype.init.apply(this, arguments);
      }
   });
});
javascript 复制代码
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 parent
         UIComponent.prototype.init.apply(this, arguments);
         // set data model
         const oData = {
            recipient : {
               name : "World"
            }
         };
         const oModel = new JSONModel(oData);
         this.setModel(oModel);

         // set i18n model
         const i18nModel = new ResourceModel({
            bundleName: "sap.ui.demo.walkthrough.i18n.i18n"
         });
         this.setModel(i18nModel, "i18n");
      }
   });
});

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

javascript 复制代码
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 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);
      }
   });
});

修改index.js

webapp\index.js

javascript 复制代码
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.

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

相关推荐
Seele_10183 天前
RAP - 报表示例
sap·abap
SAP_奥维奥科技3 天前
破局传统制造,赋能智能转型——机加工企业智能工厂升级实施方案重磅出炉
sap·智能制造·sap管理系统·sap管理系统软件·sap实施服务商推荐
SAP_奥维奥科技4 天前
如何选择适合自己企业的SAP实施服务商?
sap
SAP_奥维奥科技5 天前
详解SAP Business One:信用额度管理
sap·sap管理系统·sap business one·sap管理系统软件·sap实施服务商
爱喝水的鱼丶6 天前
SAP-ABAP:高效开发指南:全局唯一标识符ICF_CREATE_GUID函数的全面解析与实践
运维·服务器·开发语言·数据库·sap·abap·开发交流
LilySesy6 天前
【SAP-MOM项目】二、接口对接(中)
开发语言·python·pandas·restful·sap·abap
Lisson 36 天前
VF01修改实际开票数量增强
java·服务器·前端·abap
Henry-SAP8 天前
SAP(ERP) 组织结构业务视角解析
大数据·人工智能·sap·erp·sap pp
爱喝水的鱼丶10 天前
SAP-ABAP:掌握BAPI_OUTB_DELIVERY_CONFIRM_DEC:解锁SAP自动化发货的核心钥匙
运维·学习·sap·abap·交流学习
SAP_奥维奥科技11 天前
详解SAP Business One:采购费用的处理方式
sap