0

I have a sap.m.VBox control, of which the items aggregation is bound to an ODataModel dataset, and as such is being populated by a sap.m.HBox template control containing multiple sap.m.Input controls (which are bound to the respective ODataModel's dataset properties)

In code:

<VBox items="{/My_ODatamodel_Dataset}">
    <items>
        <HBox>
            <Input value="{property1} change="doSomething"/>
            <Input value="{property2} change="doSomething"/>
            <Input value="{property3} change="doSomething"/>
        </HBox>
    </items>
</VBox>

(the OData dataset has a filter applied, but I left it out for brevity)

The rendered result will thus be a VBox with multiple rows of HBoxes (one for each entry in my OData set) containing the input fields for these entries.

In my controller, I have the doSomething method:

doSomething: function(oEvent) {
    var oCurrentContext  = oEvent.getSource().getBindingContext();
    var sSomeHiddenValue = oCurrentContext().getProperty("property4");
    // continue to do something special with hidden property 4 
}

However, to my surprise oEvent.getSource().getBindingContext() returns undefined...

I suppose I'm overlooking something here, but it does work when using a JSON model instead of an OData model...

What I'm trying to achieve, is to get a property value from the current entry in which I'm making a change. Is there a different way of doing so using an OData model?

Any help is highly appreciated!

Qualiture
  • 4,900
  • 7
  • 27
  • 38
  • @boghyon Technically, I'd say the referenced topic is a duplicate instead, since that one is asked 2 years after this question ;-) – Qualiture Mar 28 '18 at 14:28
  • I agree :) But yea, technically. When it comes to helping future readers, however, the question with the better answer would be more appropriate for them. Hence, the date of the question does not always decide which question gets marked as a "duplicate". You can read more about it in https://meta.stackexchange.com/q/147643 and https://meta.stackoverflow.com/q/348561 – Boghyon Hoffmann Mar 28 '18 at 15:25
  • You're right :) – Qualiture Mar 29 '18 at 12:03

1 Answers1

1

with the ODataModel you need to get the properties of the context from the Model, try

  var oModel = oEvent.getSource().getModel();
  var oContext = oEvent.getSource().getBindingContext();
  var sSomeHiddenValue = oModel.getProperty("property4", oContext);

hth jsp

Jasper_07
  • 2,453
  • 2
  • 18
  • 23
  • Hi John, Thanks for your swift help, and it pointed me to the right direction! Since I'm using a named model in my actual code, I modified yours to include the model name in the `getModel()` method, and that suddenly reminded my i should include the model name in the `getBindingContext()` method as well... As most often the case, the error here was between the chair and the laptop :) – Qualiture Oct 10 '14 at 09:52
  • cheers, i have had my share of PEBCAK lately :-) – Jasper_07 Oct 10 '14 at 09:58