Skip to Content
0

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

Aug 16, 2017 at 12:38 PM

35

avatar image
Former Member

Dears,

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");
oModel.setDefaultBindingMode("OneWay");
this.setModel(oModel, "CreateData");

Controller.js file

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

View.xml file

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

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
1

Hi,

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

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 :)

1