Skip to Content
avatar image
Former Member

bindElement without request

Hey,

I want to make my App offline capable. When I switch my views the bindElement() method is called and is always making a request against the backend. Is there any possiblity to set the data manually without making a request?

Thanks for your help and best regards,

David

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Oct 10, 2016 at 01:39 PM

    use json model

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 11, 2016 at 01:14 AM

    I use a JSON Model, but I'm very new to SAPUI5, so a little bit more input would be nice ;) If you have an example how to set the data manually with a JSON Model that would be nice. Thank you very much!

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 10, 2016 at 02:23 PM

    Hello David,

    you can use a json model for it, read data from backend once or you can test using hard coded data, once data is ready set that data to json model and set this model to view.

    lets say you have json data is like below, then you can do bindElement as below:

    oData={"results":[]};
    .bindElement("/results");

    Hope this will help you.

    Regards,

    Akhilesh

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 10, 2016 at 07:57 PM

    Hey Akhilesh,

    thanks for your reply. I've tested your suggestion, but it stills triggers a HTTP request... any other ideas how I can solve this issue?

    Thanks for your help and best regards,

    David

    Add comment
    10|10000 characters needed characters exceeded

    • 1) if you are trying to load data from server once and use json model

      I think you didn't changed binding code in attachRoutePatternMatched function, that still pointing to oDataModel navigation property,

      instead of binding view with the navigation property (oView.bindElement(sObjectPath)), do something like below:

      //set json model(may be named model) to view : 
      oView.setModel(oJsonModel, "jModel");
      oView.bindElement("/jModel>/results");

      using above code data will be pulled from json model only.

      2) if you don't want any sever request even for initial load and working with json model(with hard coded data)

      then, replace oDataModel with json model(with hard coded data) in component.js file only, and replace navigation property with json model.

      Hope will be helpful.

      -Akhilesh

  • Oct 12, 2016 at 01:49 PM

    are u loading data from server?

    if yes, how can u avoid the http request?

    Add comment
    10|10000 characters needed characters exceeded