SAPUI5: How to get event notification in case of ODataModel changes?

I am looking for an event to be selected if ODataModel is changed (client side). The problem is that in my application there are many different fields that can edit the model. In the case of a model change, I will have a function registered that activates the "Save" button. The Save button calls the submitChanges () function of the model (I use TwoWayBinding mode).

Currently, I have only discovered the hasPendingChanges () method, but could not register the event.

What is the proposed solution to solve this problem?

For processing changes in each control, the Input does not look like this because it is easy to forget some fields (at least if someone else will support the code).

My current solutions look something like this:

sap.ui.model.odata.ODataModel.extend("MyModel", { setProperty : function(sPath, oValue, oContext) { sap.ui.model.odata.ODataModel.prototype.setProperty.apply(this, [sPath, oValue, oContext]); // do something here } }); 
+7
source share
2 answers

You can use sap.ui.model.Binding.attachChange()

 var binding = new sap.ui.model.Binding(model, "/", model.getContext("/")); binding.attachChange(function() { saveButton.setVisible(true); saveButton.setEnabled(true); //or anything else }); 

The function is called every time the model changes, for example. calling model.setProperty(key, value) .

https://openui5.netweaver.ondemand.com/#docs/api/symbols/sap.ui.model.Binding.html

+8
source

I would suggest to do this instead of the model (as you say, it is called several times), call it in each control that has a binding, using the "change" property, where you must specify your verification method.

0
source

Source: https://habr.com/ru/post/977873/


All Articles