我正在链接资源,如 图片 但我遇到了一个问题。
通常情况下,路径是这样的,比如说。
return "css/style1.css"; // for a stylesheet inside the folder css
return "img/image.jpg"; // for a image inside the 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"