cancel
Showing results for 
Search instead for 
Did you mean: 

Load JSON file in Web IDE extension/feature

0 Kudos

Hello,

I'm trying to load a JSON file into my JSON model in my Web IDE extension. However the normal way to load JSON (in ui5 applications) does not work in extensions since the url is not resolved properly, I get a 404 error and I see that the url is incorrect. I must be missing something in my plugin definition?

The following code does not work:

this.oModel = new sap.ui.model.json.JSONModel();

this.oModel.loadData("plugin_load_from_json/model/myJSON.json",{},false);

In order to load the JSON file I have to load it like this:

this.oModel = new sap.ui.model.json.JSONModel();

this.oModel.loadData(sap.ui.loader._.getResourcePath("plugin_load_from_json/model/myJSON.json"),{},false);

using sap.ui.loader._.getResourcePath() in order to resolve the correct url.

is there some config missing?

To reproduce you can create a "Web IDE Extension" with "sample code". Then add a json file, and the code above to load the file. See attached picture

/regards
Andri

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member341000
Participant
0 Kudos

Hi,

You can use this code to resolve the file URL:

require.toUrl("<plugin name>/<path to file>")

The plugin name is taken from the plugin.json file.

The path to the file in your case is model/myJSON.json.

Best regards,
Tal

0 Kudos

Hello Tal,

Yes this also works, but in my oppinion just marginally better.

Is this the official way to do this? I would expect that you don't have to manually resolve the URL.

regards,
Andri