Skip to Content
0

bindElement without request

Oct 10, 2016 at 01:26 PM

176

avatar image

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

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

5 Answers

Jun Wu Oct 10, 2016 at 01:39 PM
0

use json model

Share
10 |10000 characters needed characters left characters exceeded
David B Oct 11, 2016 at 01:14 AM
0

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!

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

Hi David, it's pretty much impossibile that your app is making server side request if you're using a JSONModel ;)

Are sure you're not using an oData Model?

0
Akhilesh Upadhyay Oct 10, 2016 at 02:23 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
David B Oct 10, 2016 at 07:57 PM
0

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

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

can you share your code please?

-Akhilesh

0
Akhilesh Upadhyay

I found the problem why a HTTP request is still triggered...

In my model I have a navigation attribute. When I switch the view, the data is initialized, but the data for the navigation attribute is always requested from backend (but it is already available in my JSON Model).

Is there any possibility to access the objects from my JSON Model and no HTTP request is triggered?

Thank you very much and best regards,

David

0

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

0
Jun Wu Oct 12, 2016 at 01:49 PM
0

are u loading data from server?

if yes, how can u avoid the http request?

Share
10 |10000 characters needed characters left characters exceeded