on 03-24-2017 12:58 PM
We are using the eclipse IDE and have a standard project set up. However, we are able to load in a json file. The statement that performs the load does not cause an error as such, as processing continues, but we do get a 404 error in the console when debugging.
I json file is stored in the 'model' subdirectory of the project, and the json file is called Testmodel.json. We have tried:
oModel1.loadData("model/Testmodel.json");
oModel1.loadData("Testmodel.json");
var oModel1 = new sap.ui.model.json.JSONModel("Testmodel.json");
var oModel1 = new sap.ui.model.json.JSONModel("model/Testmodel.json");
And we have attempted to load it by setting the model in the manifest, but alas no joy.
I'm pretty sure it's some kind of resource issue. Our resource settings in the index.html are:
<scriptid="sap-ui-bootstrap"
src="resources/sap-ui-cachebuster/sap-ui-core.js"
data-sap-ui-libs="sap.m"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-compatVersion="edge"
data-sap-ui-resourceroots='{"tabLayout": ""}'
data-sap-ui-bindingSyntax="complex">
</script>
But so far nothing I can do will load a json file.
Thanks to everyone that replied. I have actually tried all those options, of which none worked. However, I have resolved it, and it was incredibly simple, but cause so much grief.
In out index.html file we had an entry saying:
data-sap-ui-resourceroots='{"tabLayout": ""}'
Which we changed it to:
data-sap-ui-resourceroots='{"tabLayout": "."}'
with the full-stop having the effect. We had previously tried this with “./”, but that did not work.
So now our json file can be loaded via all of the methods I mentioned in my post, including declaring a model in the manifest.
Regards to all.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
var oRootPath = jQuery.sap.getModulePath("replace.with.your.namesapce"); //could be "tabLayout" in your case
YOURJSONMODEL.loadData(oRootPath + "/model/Testmodel.json", null, false);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gary,
Normally the structure for your application will be like this projectname/webapp/model/yourjsonfile.json
in model folder you will keep your json file. If structure is like above you can use try like this
var oModel=new sap.ui.model.json.JSONModel("projectname/webapp/model/yourjsonfile.json");if you want to bind this to any control then get the id of that control and bind like this
//model without name
var selectid= this.getView().byId("controlsidtobind").setModel(oModel);Thanks,Abul Ehtesham
Thanks,You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gary,
While defining the path please maintain like this "/projectname/model/testmodel.json".
Kindly check and let me know if there is any issue.
Thanks,
Deepak Raj.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.