我正在链接到使用SAPUI5制作的应用程序中的资源,例如css或图像,但是我遇到了问题。通常,SAPUI5中的路径例如是
return "css/style1.css"; #for a stylesheet inside folder css
return "img/image.jpg"; #for a image inside folder img
并且一旦部署了应用程序,它就可以正常工作,但是当都未使用SAP Web IDE运行时都找不到时,则网络代码为404。因此,要在SAP Web IDE中运行以显示样式和图像,路径为:
return "../../../../../webapp/css/style1.css"; #for a stylesheet inside folder css
return "../../../../../webapp/img/image.jpg"; #for a image inside folder img
并且它是正在使用SAP Web IDE运行的工作,但是不干净不能确保一旦部署就可以正常工作能够使用标准链接并在SAP Web IDE中运行应用程序以在部署之前掌握结果,这是否可能是一种配置或技巧?
存在一种为此创建模型的解决方案:在model.js中:
createImageRoot: function() {
var oModel = new JSONModel({
path: sap.ui.require.toUrl("the.namespace") // available since 1.58. Otherwise, use jQuery.sap.getModulePath instead.
});
oModel.setDefaultBindingMode("OneWay");
return oModel;
},
在Component.js中,添加init方法
this.setModel(models.createImageRoot(), "imageRoot");
然后例如:
return this.getView().getModel("imageRoot").getProperty("/path") + "img/image.jpg"