2016-09-08 66 views
0

我需要在我的应用程序中使用Here Maps Javascript API库。当我独立运行应用程序时它运行良好(因为我将它包含在index.html中)。但是,当我将其部署在HANA Cloud Platform上并尝试在HCP Portal站点内运行时,它会失败。 我知道我需要加载库文件Component.js因为没有使用index.html。我的问题是,在开始绘制地图之前,我需要加载4个不同的js文件和一个样式表。我正在使用jQuery.sap.includeScript()jQuery.sap.includeStyleSheet()函数来执行此操作,但在加载库文件(请参阅chrome中的“网络”选项卡上的状态为“挂起”)之前调用rootview的onInit和onAfterRendering()。在SAPUI5中加载第三方库

我跟着后下:

UsingjQuery.sap.includeScript().then() in HCP Firori Launchpad

我如何可以加载/初始化库文件被加载后,才视图。

在component.js中完成所有这些操作是否正确? manifest.json在实现这个过程中扮演什么角色。

任何示例都会有所帮助。 在此先感谢。

我的组件初始化代码如下:

init: function() { 
      // call the base component's init function 
      UIComponent.prototype.init.apply(this, arguments); 
      var that = this; 
      //Load the here maps library 
      jQuery.sap.includeScript("https://js.api.here.com/v3/3.0/mapsjs-core.js", "hereMapsCore", $.proxy(function(succ) { 
       jQuery.sap.includeScript("https://js.api.here.com/v3/3.0/mapsjs-service.js", "hereMapsService", $.proxy(function(succ) { 
        jQuery.sap.includeScript("https://js.api.here.com/v3/3.0/mapsjs-ui.js", "hereMapsUi", $.proxy(function(succ) { 
         jQuery.sap.includeScript("https://js.api.here.com/v3/3.0/mapsjs-mapevents.js", "heremapsEvent", $.proxy(function(succ) { 
          jQuery.sap.includeStyleSheet("https://js.api.here.com/v3/3.0/mapsjs-ui.css", "hereMapscss", $.proxy(function() { 
           // UIComponent.prototype.init.apply(this, arguments); 
           // set the device model 
           this.setModel(models.createDeviceModel(), "device"); 
           var a = this; 
          }, this)); 
         }, this), function(oErr) { 
          MessageBox.alert("Map File not loaded"); 
         }); 
        }, this), function(oErr) { 
         MessageBox.alert("Map File not loaded"); 
        }); 
       }, this), function(oErr) { 
        MessageBox.alert("Map File not loaded"); 
       }); 
      }, this), function(oErr) { 
       MessageBox.alert("Map File not loaded"); 
      }); 
     } 

回答

0

您可以作为Developer Guide表12中描述的组件描述符manifest.json添加所需的资源:

相对URL的组件,考虑到embeddedBy如果填充,指向js(JavaScript)和css资源是应用程序需要指定强制uriid(可选)用于CSS。 JavaScript文件由require机制加载。 CSS文件作为链接标签添加到HTML页面的头部。资源是相对于manifest.json文件的位置已解析。

如果您对绝对URI有问题,您可以将JavaScript和CSS文件存储在组件下方的UI5项目中,并使用相对路径。

实施例:在sap.ui5/resources部分此加入的manifest.json:

"sap.ui5": { 
    "resources":{ 
    "js": [ 
     { 
     "uri": "lib/otherScript.js" 
     }, 
     { 
     "uri": "https://js.api.here.com/v3/3.0/mapsjs-core.js" 
     } 
    ], 
    "css": [ 
     { 
     "id": "myCustomCSS", 
     "uri": "css/style.css" 
     }, 
     { 
     "uri": "https://js.api.here.com/v3/3.0/mapsjs-ui.css" 
     } 
    ] 
    } 
}