I have a model I use in a controller and have setup both model change and property change event functions on that model like so:
onInit: function() {
var oData = {
"Products": [
{
"ProductID": 1,
"ProductName": "Chai",
"SupplierID": 1,
"CategoryID": 1,
"QuantityPerUnit": "10 boxes x 20 bags",
"UnitPrice": "18.0000",
"UnitsInStock": 39,
"UnitsOnOrder": 0,
"ReorderLevel": 10,
"Discontinued": false
}
]
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(oData);
this.attachModelEventHandlers(oModel);
}
attachModelEventHandlers: function(oModel){
oModel.attachPropertyChange(this.handlePropertyChanged, this);
var binding = new sap.ui.model.PropertyBinding(oModel, "/", oModel.getContext("/"));
binding.attachChange(this.handleDataChanged, this);
},
handlePropertyChanged: function(oEvent) {
// Do whatever here...
}
handleDataChanged: function(oEvent) {
// Do whatever here...
}
I have bound the model to a table and everything works fine... if I update properties, the relevant model change and property change events fire.
If I use something like below to update a property however, only the handleDataChanged event function will fire, not the handlePropertyChanged event function:
oModel.setProperty("Products/0/ProductName", "SomeNewValue");
Any idea why? Is my PropertyBinding correct?