Skip to Content

SAPUI5 not all JSON file data is showing up in the controller

Aug 16, 2017 at 12:38 PM


avatar image
Former Member


I've created JSON model in my webIDE project. and I've used only two of its attributes in my the view. But when I try to call JSON file data in the controller the consol.log shows only the two used items and ignores the rest.

JSON file:

	"DocNum": "111",
	"FormNo": "10",
	"EmpNum": "00020000",
	"Amount": "1000.00",
	"Currency": "USD",
	"Beneficiary": "0020000050",
	"ReqFor": "D"

Component.js file

var oModel = new JSONModel("./model/CreateData.json");
this.setModel(oModel, "CreateData");

Controller.js file

PostData: function(oEvent){        		
    var oModel = this.getOwnerComponent().getModel("CreateData");

View.xml file

<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:html="" controllerName="PayTest.controller.CreateView">
  <Page title="{CreateData>/Beneficiary}" showNavButton="true" navButtonPress="onNavBack">
	<Button text="{CreateData>/EmpNum}" width="100px" id="__button0" press="PostData"/>

Is there is any explanation for that?

Note: same behaviour when loading it in the manifest.json file

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Emanuele Ricci Aug 16, 2017 at 01:40 PM


var oModel = this.getOwnerComponent().getModel("CreateData");

will just print the oModel object. If you want to access the JSON inside that model you can do 3 things:

1) oModel.getProperty("/") that will give you back the whole json

2) oModel.getProperty("/YourPropertyName")

3) oModel.getData() will give you back the whole json too

I tried locally on my WebIDE project and everything work as intended (at least as you want).

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thank you :)