Skip to Content

how to retrieve data from JSON model mvc

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Apr 09 at 11:16 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 09 at 11:40 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 10 at 01:48 AM

    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.

    Add comment
    10|10000 characters needed 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