Skip to Content

How to send JSON model from one view controller to another view controller .??

Hi

I need to fetch JSON model of one view and need to use it in another view controller, I have used sap.ui.getCore().setModel(). But some of them are suggested that its not best practice to set model to core.

So is there any other way to send JSON model to another view controller.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Aug 08, 2017 at 06:46 PM

    Like Saurabh said, you could declare the model in the Component.js and set it (this.setModel("modelName")) and then create an instance using this.getOwnerComponent().getModel("modelName") in the controller where you want to use it.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 08, 2017 at 02:53 PM

    Possible with what Saurabh mentioned above.

    But you also need to take care that the UI flow always goes through the view where the model is being set.

    Otherwise, if you navigate to the view which consumes the model directly via the URL, the model won't be available.

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 08, 2017 at 06:07 AM

    Either declare your JSON model in the Component.js file or within the manifest.json file. Models declared within any of these are globally available within the entire application. Refer SAPUI5 SDK

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Nandish m

      You should do the following:

      - on the component var oModelEx = new JSONModel(); this.setModel(oModelEx, "oModelEx");

      - on the 2 view var oModelEx = this.getOwnerComponent().getModel("oModelEx"); oModelEx.setProperty("/property", value)

      - on the 3 view var oModelEx = this.getOwnerComponent().getModel("oModelEx"); var sProperty = oModelEx.getProperty("/property");

      I hope this could help you.