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?
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?
Share Improve this question asked Mar 2, 2015 at 0:17 JorgJorg 7,2504 gold badges47 silver badges66 bronze badges 2-
1
See the answer by @matbtt; you should never update model properties directly, always use
model.setProperty("/path/to/your/property", oSomeData);
-- andgetProperty("/path/to/your/property");
for retrieving data from the model – Qualiture Commented Mar 10, 2015 at 8:39 - For other readers: this answer might also help: stackoverflow./a/48157104/5846045 – Boghyon Hoffmann Commented Mar 16, 2019 at 11:32
2 Answers
Reset to default 5Why 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.
Always good practice to call updateBindings()
whenever data is updating. Try:
model.updateBindings()