openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

Find out if current binding is local or not

Open Myge91 opened this issue 10 years ago • 1 comments

Hello everyone,

right now I have an aggregationBinding on a sap.m.VBox. The data comes from an oData service. I also have an add button to add data to the VBox. So at this point we have a mixed list with data that we have to update and data we have to insert. Also I want to delete a certain element in the VBox. So I need to know if the current element I want to delete comes from the oData service or if I have created it with oModel.createEntry. Unfortunatelly I haven't found a function where I can find out if a certain element in the VBox already exists.

My code to delete a certain entry looks like this:

onDeletePress: function(oEvent) {
        var oBindingContext = oEvent.oSource.getBindingContext();
        var bIsLocal = this.isLocal(oBindingContext);
        if (bIsLocal) {
            this.getView().getModel().deleteCreatedEntry(oBindingContext);
        } else {
            this.getView().getModel().remove(oBindingContext.sPath);
        }
      this.getVBox().removeItem(oEvent.oSource.getParent().getParent().getParent());
    }

    isLocal: function(oBindingContext) {
        return this.getView().getModel().getProperty(oBindingContext.sPath).__metadata.created !== undefined;
    }

I thought this could be an enhancement to openui5 to add a method that checks if the binding comes from the oData service or from a createEntry?

Myge91 avatar Jul 21 '16 08:07 Myge91

Hi @Myge91 ,

what you want is unfortunately not supported in UI5. After binding, you should control your aggregations over the model and not with aggregation mutators. Also we do not have two-way aggregation binding at the moment that could fix your problem as well.

For your use case I would suggest to read(and later write) the data with ODataModel and set it to a JSONModel which is bound to your UI.

BTW, please use github for issues and e.g. stackoverflow for consulting questions.

aborjinik avatar Jul 22 '16 09:07 aborjinik