標籤:
本次對之前學習的SAP UI5架構知識進行簡單小結,以及重點部分知識的梳理。
1、在UI5使用過程中,命名空間的概念很重要。
2、一般的sap組件引用格式如下:
sap.ui.define([ "sap/ui/core/UIComponent", "sap/ui/model/json/JSONModel", "sap/ui/model/resource/ResourceModel"], function (UIComponent, JSONModel, ResourceModel)
define後每引用sap的一個組件,後面的function就要傳入一個對應的參數。
3、以下是component使用的基本架構:
sap.ui.define([ "sap/ui/core/UIComponent"], function (UIComponent) { "use strict"; return UIComponent.extend("", { init : function () { // call the init function of the parent UIComponent.prototype.init.apply(this, arguments);} });});
Component的構建流程如上,extend UIComponent這個架構,裡面init為初始化函數,裡面可以設定其他屬性(包括配置模型等),如下:
sap.ui.define([ "sap/ui/core/UIComponent", "sap/ui/model/json/JSONModel", "sap/ui/model/resource/ResourceModel"], function (UIComponent, JSONModel, ResourceModel) { "use strict"; return UIComponent.extend("sap.ui.demo.wt.Component", { metadata : {rootView: "sap.ui.demo.wt.view.App"}, init : function () { // call the init function of the parent UIComponent.prototype.init.apply(this, arguments); // set data model var oData = { recipient : { name : "World" } }; var oModel = new JSONModel(oData); this.setModel(oModel); // set i18n model var i18nModel = new ResourceModel({ bundleName : "sap.ui.demo.wt.i18n.i18n" }); this.setModel(i18nModel, "i18n"); } });});
4、注意manifest檔案在一個應用中的重要性,manifest.json是app的設定檔。
HTML5開發移動web應用——SAP UI5篇(8)