cancel
Showing results for 
Search instead for 
Did you mean: 

how to set relative path in sapui5?

honam_yu
Explorer
0 Kudos
4,636

hi experts

I make sapui5 project above.

I access products.json file from App.controller.js

I use relative path --> ../json/products.json. but I cannot load json file.

And I use ./json/products.json.

why different general relative path?

thanks

Accepted Solutions (1)

Accepted Solutions (1)

prashil
Product and Topic Expert
Product and Topic Expert

Hi Honam,

Please try with sap.ui.require.toUrl("com/prashil/test/json/products.json") where my namespace is "com.prashil.test".

Thanks

Prashil

honam_yu
Explorer
0 Kudos

Hi Prashil

Thank you. It is correct.

Best regards

Honam

Answers (2)

Answers (2)

prashil
Product and Topic Expert
Product and Topic Expert

Hi Honam,

The best way to have the json file loaded is already have it resolved with respect to your project module path.

var sProductsJsonPath = jQuery.sap.getModulePath("com.prashil.test", "/json/products.json");

var oProductModel = new sap.ui.model.json.JSONModel(sProductsJsonPath);

This way you no matter if your UI5 app is launched from Fiori Launchpad or standalone or SCP, it will always resolve the proper reference.

Thanks

Prashil

honam_yu
Explorer

Hi Prashil

thank you your replay

I solve my problem.

and I looked for the latest API, jQuery.sap is deprecated as of version 1.58.

Is there any other way not deprecated?

thanks

junwu
Active Contributor

var path=sap.ui.require.toUrl("json/products.json")

new JSONModel(path)

honam_yu
Explorer
0 Kudos

Hi Jun Wu

thank you your replay

but path is added "resources" more

I couldn't solve the problem

thanks

junwu
Active Contributor
0 Kudos

can you get the data?