1
votes

I'm using SAPUI5 to make an application and I'm having an issue with an update to the model not being reflected immediately in the view.

A slightly simplified scenario: I created a text field that is taking its text from the model:

currentText = new sap.m.Text({
    width: '100%',
    text: '{/currentTrip/perHour}'
});

Then I create a select and attach a change handler:

sourceSelect.attachChange(oController.changeTripSource);

Inside that controller function I'm updating the view model:

var model = this.getView().getModel().getData();
model.currentTrip.perHour = 5;

All the things I do with this number flowing from this change event work (like updating a connected graph, which uses this number directly). The view itself however will not reflect the change to the model until I take another action like push a button or something. I'm not understanding why that is, or what triggers UI5 to check the changed values to the model and update the view. Does anyone have a fix for this?

2
See the answer by @matbtt; you should never update model properties directly, always use model.setProperty("/path/to/your/property", oSomeData); -- and getProperty("/path/to/your/property"); for retrieving data from the modelQualiture
For other readers: this answer might also help: stackoverflow.com/a/48157104/5846045Boghyon Hoffmann

2 Answers

5
votes

Why don't you call setProperty() on the model directly? This saves you superfluous calls to update your bindings as the model will do it internally.

model.setProperty("/currentTrip/perHour", 5);

By the way, I don't see why updateBindings() shall work while refresh does not. Both methods call the checkUpdate() behind the curtains.

2
votes

Always good practice to call updateBindings() whenever data is updating. Try:

 model.updateBindings()