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.

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

相关推荐
数字化转型20257 天前
Alternative Reconciliation Accounts 备选统驭科目
sap
小九不懂SAP18 天前
6、定义字段状态变式
sap·s4
lu_rong_qq1 个月前
SAP B1 三大基本表单标准功能介绍-物料主数据(下)
数据库·sap·erp
1314lay_10071 个月前
FUNCTION_ALV 下拉框的实现
abap
Fireworks_me1 个月前
SAP 有趣的‘bug‘ 选择屏幕输入框没了
abap
仁,义1 个月前
其它特殊库存
sap·库存管理·特殊库存
李安迪是大神1 个月前
上传PDF、DOC文件到SAP HCM系统中案例
pdf·word·sap·abap·sap erp
集信通1 个月前
SAP和致远OA系统集成案例
人工智能·自动化·区块链·sap
数字化转型20252 个月前
SAP BRIM用于应收账款AR收入中台
大数据·microsoft·sap
荀彧原名苟或2 个月前
SAP MIGO屏幕增强的具体实施步骤介绍(SE19:MB_MIGO_BADI) <转载>
java·数据库·缓存·sap·abap