天天看點

通過 url 參數 parameters 和 script tag 屬性來配置 SAP UI5 運作時

Configuration of the SAPUI5 Runtime using URL parameters

建立一個 SAP UI5 應用,index.html 實作如下圖所示:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8' />

<script
    src="resources/sap-ui-core.js" 
    id="sap-ui-bootstrap"
    data-sap-ui-libs="sap.m">   
</script>

<script>
    // Set the log level to INFO
    jQuery.sap.log.setLevel(jQuery.sap.log.Level.INFO);

    // Get reference the Core object
    var oCore = sap.ui.getCore();

    // Read Core
    var oLibMap = oCore.getLoadedLibraries();
    for (key in oLibMap) {
        jQuery.sap.log.info("Loaded Library name", key);
    }
    jQuery.sap.log.info("Has model?", oCore.hasModel().toString());
    jQuery.sap.log.info("Is mobile?", oCore.isMobile().toString());

    // Read Configuration object from the Core
    var oConfig = oCore.getConfiguration();
    jQuery.sap.log.info("Accessibility", oConfig.getAccessibility().toString());
    jQuery.sap.log.info("Debug", oConfig.getDebug().toString());
    jQuery.sap.log.info("Language", oConfig.getLanguage());
    jQuery.sap.log.info("Locale", oConfig.getLocale());
    jQuery.sap.log.info("Version of SAPUI5 Framework", oConfig.getVersion());
    jQuery.sap.log.info("Theme", oConfig.getTheme());
    jQuery.sap.log.info("User agent", navigator.userAgent);

    // Reset the log level to default of ERROR 
    jQuery.sap.log.setLevel(jQuery.sap.log.Level.ERROR);
</script>

</head>
<body class="sapUiBody" role="application">
    <div id="content"></div>
</body>
</html>
      

使用如下的 url 進行測試:

http://localhost:8080/sapui5.configurl.demo?sap-ui-accessibility=false&sap-ui-debug=false&sap-ui-language=de&sap-ui-theme=sap_bluecrystal&data-sap-ui-xx-fakeOS=ios

請根據您的伺服器配置使用端口号。 加載 index.html 将在開發者工具控制台中列印日志。 該 URL 包含多個配置參數(格式為 sap-ui-PARAMETER-NAME = ”value”),由第二個腳本區域中的代碼讀取。 日志級别從預設的 ERROR 更改為 INFO 并傳回以列印 jQuery.sap.log.info () 語句。

通過 url 參數 parameters 和 script tag 屬性來配置 SAP UI5 運作時

Configuration of the SAPUI5 Runtime using script tag attributes

index.html:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8' />

<script
    src="resources/sap-ui-core.js" 
    id="sap-ui-bootstrap"
    data-sap-ui-libs="sap.m" 
    data-sap-ui-accessibility="false"
    data-sap-ui-debug="false"
    data-sap-ui-language="de"
    data-sap-ui-theme="sap_bluecrystal" 
    data-sap-ui-xx-fakeOS="ios">    
</script>

<script>
    // Set the log level to INFO
    jQuery.sap.log.setLevel(jQuery.sap.log.Level.INFO);

    // Get reference the Core object
    var oCore = sap.ui.getCore();

    // Read Core
    var oLibMap = oCore.getLoadedLibraries();
    for (key in oLibMap) {
        jQuery.sap.log.info("Loaded Library name", key);
    }
    jQuery.sap.log.info("Has model?", oCore.hasModel().toString());
    jQuery.sap.log.info("Is mobile?", oCore.isMobile().toString());

    // Read Configuration object from the Core
    var oConfig = oCore.getConfiguration();
    jQuery.sap.log.info("Accessibility", oConfig.getAccessibility().toString());
    jQuery.sap.log.info("Debug", oConfig.getDebug().toString());
    jQuery.sap.log.info("Language", oConfig.getLanguage());
    jQuery.sap.log.info("Locale", oConfig.getLocale());
    jQuery.sap.log.info("Version of SAPUI5 Framework", oConfig.getVersion());
    jQuery.sap.log.info("Theme", oConfig.getTheme());
    jQuery.sap.log.info("User agent", navigator.userAgent);

    // Reset the log level to default of ERROR 
    jQuery.sap.log.setLevel(jQuery.sap.log.Level.ERROR);
</script>

</head>
<body class="sapUiBody" role="application">
    <div id="content"></div>
</body>
</html>
      

在浏覽器中打開如下網址 http://localhost:8080/sapui5.config.demo/

請根據您的伺服器配置使用端口号。 加載 index.html 将在開發者工具控制台中列印日志。 第一個腳本區域(也稱為 Bootstrap)中的代碼包含多個配置參數(格式為 data-sap-ui-PARAMETER-NAME = ”value”),由第二個腳本區域中的代碼讀取。 日志級别從預設的 ERROR 更改為 INFO 并傳回以列印 jQuery.sap.log.info () 語句。