Step 6: Modules

介绍

In SAPUI5, resources are often referred to as modules. In this step, we replace the alert from the last exercise with a proper Message Toast from the sap.m library. The required modules are enabled to be loaded asynchronously.

1.练习效果

Step 6: Modules - 第1张  | 优通SAP

2.源码

You can view and download all files at Walkthrough – Step 6.

webapp/controller/App.controller.js

We extend the array of required modules with the fully qualified path to
sap.m.MessageToast. Once both modules,
Controller and MessageToast, are loaded, the
callback function is called and we can make use of both objects by accessing the
parameters passed on to the function.

This Asynchronous Module Definition (AMD) syntax allows to clearly separate the
module loading from the code execution and greatly improves the performance of the
application. The browser can decide when and how the resources are loaded prior to
code execution.

3. Conventions

  • Use sap.ui.define for controllers and all other JavaScript
    modules to define a global namespace. With the namespace, the object can be
    addressed throughout the application.

  • Use sap.ui.require for asynchronously loading dependencies
    but without declaring a namespace, for example code that just needs to be
    executed, but does not need to be called from other code.

  • Use the name of the artifact to load for naming the function parameters
    (without namespace).

留下一个回复

你的email不会被公开。

4 − three =