1. 程式人生 > >HTML5開發移動web應用——SAP UI5篇(8)

HTML5開發移動web應用——SAP UI5篇(8)

cti 空間 () snippet javascrip oot article rac 構建

本次對之前學習的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.jsonapp的配置文件。

HTML5開發移動web應用——SAP UI5篇(8)