HTML5 developing mobile Web Applications--sap UI5 (7)

Source: Internet
Author: User

The SAPUI5 supports encapsulation of components with component. To encapsulate a component, the basic code for component is as follows:

Sap.ui.define ([   "sap/ui/core/uicomponent"], function (UIComponent) {   "use strict";   Return Uicomponent.extend ("", {      init:function () {         //Call the Init function of the parent         Uicomponent.proto Type.init.apply (this, arguments);});}   );

Analyze the code implications of the component framework, referencing the uicomponent base space in the core. Components are written in uicomponent.extend, i.e. they are extended.

We tried to encapsulate the previous application as a component. Create a new Component.js file with code such as the following:

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 () {         UIComponent.prototype.init.apply (this, arguments);         var oData = {            recipient: {               name: "World"            }         };         var Omodel = new Jsonmodel (oData);         This.setmodel (Omodel);         var I18nmodel = new Resourcemodel ({            bundlename: "sap.ui.demo.wt.i18n.i18n"         });         This.setmodel (I18nmodel, "i18n");});   
We put the initialization function in the original Controller.js file, the data model binding configuration and so on Component.js. Corresponding changes to the Controller.js file:

Sap.ui.define ([   "Sap/ui/core/mvc/controller",   "sap/m/messagetoast"], function (Controller, messagetoast) {   "Use strict";   Return Controller.extend ("Sap.ui.demo.wt.controller.App", {      onshowhello:function () {         var obundle = This.getview (). Getmodel ("i18n"). Getresourcebundle ();         var srecipient = This.getview (). Getmodel (). GetProperty ("/recipient/name");         var sMsg = Obundle.gettext ("Hellomsg", [srecipient]);         Messagetoast.show (SMSG);});   
In the Controller.js file, only the functions that need to be used in this project are retained. This makes the logic of each file in the project clearer.

In the index.html. We can call component directly:

<script>         Sap.ui.getCore (). Attachinit (function () {            new Sap.ui.core.ComponentContainer (               name: " SAP.UI.DEMO.WT "            }). Placeat (" content ");         });      </script>
In SAP Fiori applications. Each application has a configuration file that is Manifest.json. It defines the project configuration information for some columns.

The manifest file for this example is as follows:

{  "_version": "1.1.0",  "Sap.app": {"_version": "1.1.0", "id": "SAP.UI.DEMO.WT",//define namespace "type": "Application" , "i18n": "I18n/i18n.properties", "title": "{{appTitle}}", "description": "{{appdescription}}", "Applicationversion": {  "version": "1.0.0"}, "Ach": "Ca-ui5-doc"  },  "Sap.ui": {"_version": "1.1.0", "Technology": "UI5", " Devicetypes ": {  " desktop ": True,  " tablet ": true,  " phone ": true}," Supportedthemes ": [  " Sap_ Bluecrystal "]  },  " Sap.ui5 ": {" _version ":" 1.1.0 "," Rootview ":" Sap.ui.demo.wt.view.App "," dependencies ": {  "Minui5version": "1.30",  "libs": {"sap.m": {}}, "models": {"i18n":  {"type": " Sap.ui.model.resource.ResourceModel "," settings ": {  " bundlename ":" Sap.ui.demo.wt.i18n.i18n "}}}  }

You can see that the Manifest.json file defines a series of basic information including the UI5 version number, the data model, and so on.

The configuration file will be kept intact during the development process.

HTML5 developing mobile Web Applications--sap UI5 (7)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.