Skip to Content
-1

Problem with working with different data model in a sapui5 project

Mar 10, 2017 at 08:18 PM

130

avatar image

Hello everyone, I hope you can help me.

I have problems with the data model and the data binding,

I assign the models to the view from the onInit function of each view, but when navigating between views, created averse is no longer executed onInit, and the data binding is done with the last model created, as you could get a separate model for each model? I need to display a table with data from the moment it is entered into the view.

Attached images with controllers code and views.

Thanks in advance.

BookingHistory.controller

BookingHistory.View

Binding data in BookingHistory Table

ClientTariff.controller

ClienteTariff.view

ClienteTariff Table

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

4 Answers

Best Answer
Gowrinath Gundu Mar 11, 2017 at 07:30 AM
0

Hello Julio,

You are accessing the model at component and using it in both the views but with different alias. That would be the reason, the model at component is updated with the new data in second view and showing the same in first view(incorrect though).

Usually if we want to access model globally we use the model at component. However, in your case both views should have different data. So declare the model in the view controller itself and assign it to the view for both the views.

var model = new sap.ui.model.json.JSONModel();

model.setData(jsonBookingHistory);

this.getView().setModel(model,"modelBookingHistory");

You need to remove below code from your controller.

Similarly do it in other view.

This should work.

Regards,

Gowrinath


Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Mar 10, 2017 at 08:43 PM
0

not able to follow u

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

I hope to explain better, already with the code that I have put.

I'm working with the manifest.json for routing.
My goal is that when browsing to a view in this case BookingHistory and ClientTariff,
Show the json model data in their respective tables.

When I run for the first time, I navigate to the ClientTariff view, it runs onInit and the table is populated with the model.
Then navigate to the BookingHistory view, run onInit and the table is populated with the model.

Here comes the problem, then I navigate again to ClientTariff and the onInit is no longer executed and the table is filled with the BookingHistory model as it was the last one that was filled in the model, some properties of json match that is why some are shown Data, but still are not correct and the fields are not filled in the table.

I hope you have let me understand, please tell me what else you need to know about this context so you can help me please.
Thanks in advance

0
Akhilesh Upadhyay Mar 11, 2017 at 06:18 PM
0

Hi,

I think you can move code from onInit to RoutePatternMatched event of router, that code will execute every time whenever that particular view will be navigated.

Hope this help you.

-Akhilesh

Share
10 |10000 characters needed characters left characters exceeded
Julio Olivos Mar 13, 2017 at 09:49 PM
0

Many thanks to Gowrinath Gundu and Akhilesh Upadhyay, the two suggestions satisfy my need, and I have given two alternatives that I can apply in my project according to the ideal. Thank you very much again.

Share
10 |10000 characters needed characters left characters exceeded