Skip to Content
0

how to retrieve data from JSON model mvc

Apr 09 at 10:19 PM

50

avatar image

Hi,


I have an input control that is bound to a JSON model.

<Input id="__input0" valueLiveUpdate="true" width="200px" enabled="true" value="{local>/uEmail}"/>

var data = {uEmail: "",uPassword: ""}

var oModel = new JSONModel(data);

oModel.setDefaultBindingMode("TwoWay");



in component.js:

....setModel(oModel, "local");


Now I would like to retrieve the data from the model.

I tried

var Email = "{local>/uEmail}";

But that doesn't work. I don't know how to reference the JSON model and the data in it.

Thanks for any suggestions.

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

3 Answers

Best Answer
Tri Minh Le Apr 09 at 11:16 PM
0

Hi Mel Dodd,

This statement is wrong.

var Email = "{local>/uEmail}"; 

You can try the following statement:

var Email = this.getModel("local").getData().uEmail;

Regards,

Tri

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

Hi Tri,

It worked. Thank you.


Mel

0
Sarbjeet Singh Apr 09 at 11:40 PM
0

or you can fetch it using getProperty method also.

this.getView().getModel("local").getProperty("/uEmail");

You can always look for the docs to find out all the methods.

https://openui5.hana.ondemand.com/#/api/sap.ui.model.json.JSONModel/overview

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

Thanks, Sarbjeet

Your answer also worked.

Mel

0
Bhaskar Burra Apr 10 at 01:48 AM
0

this.getView().getModel("local").getProperty("/uEmail"); is correct in controller and <Input id="__input0" valueLiveUpdate="true" width="200px" enabled="true" value="{local>/uEmail}"/> is also correct in view. Try to move this


....setModel(oModel, "local");

to your controller and it should work. You can also use manifest.json for this.

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

Thanks, BhasKar,

As it turns out I did not need to move the setModel to the controller. Setting it in Component.js had already made it part of the View.


Mel

0