I have a List that looks as follows:
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:
How to get the bound context from the clicked item?
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>...}"
},