头图

The following figure is a piece of code used in the author's SAP UI5 development tutorial :

 var mPath = sap.ui.require.toUrl('sap/ui5/walkthrough') + "/";
console.log('Jerry: ', mPath);

This article introduces the usage scenarios and details of sap.ui.require .

Its main purpose is to resolve one or more SAP UI5 module dependencies.

The mode of operation is synchronous retrieval (probing) of values exported by a single module. When called with a single string, the string is assumed to be the ID of the loaded module, and the module's exports are returned. Returns undefined if the module has not been loaded, or if it is a non-UI5 module without a shim (eg a third-party module).

This signature variant allows synchronous access to the SAP UI5 module's export (export) without initiating module loading.

one example:

 var JSONModel = sap.ui.require("sap/ui/model/json/JSONModel");

For modules known to be UI5 modules, this signature variant can be used to check if the module is loaded.

If given an array of strings and an (optional) callback function, the string is interpreted as a module ID, and the corresponding module (and its transitive dependencies) are loaded, then the callback function will be called asynchronously. The module exports of the specified module will be provided as arguments to the callback function in the same order as they appear in the dependencies array.

The return value of asynchronous use cases is always undefined.

See an example:

 sap.ui.require(['sap/ui/model/json/JSONModel', 'sap/ui/core/UIComponent'], function(JSONModel,UIComponent) {

    var MyComponent = UIComponent.extend('MyComponent', {
      ...
    });
    ...

  });

Unified Resource Names

Some UI5 APIs use Uniform Resource Names (URNs for short) as the naming scheme for the resources they handle (eg Javascript, CSS, JSON, XML...). URN is similar to the path component of a URL:

  • They consist of a non-empty sequence of name segments
  • Segments are separated by forward slashes /
  • The name segment consists only of URL path segment characters.建议仅使用ASCII 字母(大写或小写)、数字$_-.
  • Empty name fields are not supported
  • Names consisting only of dots are reserved and must not be used for resources
  • Names are case sensitive, although the underlying server may not be
  • behavior regarding URL-encoded characters is not specified, the %ddd notation should be avoided
  • The meaning of the leading slash is undefined, but may be defined in the future. should therefore be avoided

注销
1k 声望1.6k 粉丝

invalid