1
votes

I have a List that looks as follows:

screenshot of sap.m.List in UI5

The code regarding to List:

View:

<List id="navigation"
  itemPress=".handleItemPress"
  items="{ac>/YGAC_C_JOB_PROFILE}"
>
  <StandardListItem
    type="Navigation"
    press=".handleListPress"
    title="{ac>Description}"
  />
</List>

Event handler:

handleItemPress: function (oEvent) {
  // console.log(oEvent.getSource().getMetadata().getName());
  // console.log(oEvent.getSource().getSelectedItem());
},

handleListPress: function (oEvent) {
  console.log(oEvent.getSource().getObjectBinding()); // returns null
  console.log(oEvent.getSource().getBinding());  // returns null
  console.log(oEvent.getSource().getBindingContext());  // returns null
},

What am I trying to achieve is, when I press on an item in the list, for instance "Division Switzerland", I would like to get the bound context. As you can see on the view, the List is bound to an OData service.

With UI5 browser tool, you can see, that the List is bound to a context:

Screenshot of the UI5 inspector extension

How to get the bound context from the clicked item?

1
Does this answer your question? getBindingContext() Returns undefinedBoghyon Hoffmann

1 Answers

3
votes

Both APIs getObjectBinding and getBindingContext await a model name as an argument. I.e. in your case, it should be:

handleItemPress: function(event) {
  const clickedItem = event.getParameter("listItem");
  const context = clickedItem.getBindingContext(/*modelName*/"ac"); // given items="{ac>...}"
},