on 02-20-2019 2:50 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
9 | |
9 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.