Matt Betts
Matt Betts

Reputation: 35

Get Selected Item Details

I am using the sap.m.ObjectListItem as my list items to which I have bound JSON data from an API. However, I can't find a way to get the selected item from the list when I press on an item. Even getting the key of that item would be helpful.

<List id="ObjectList"
  itemPress=".onPressDcData"
  items="{DC>/}"
>
  <ObjectListItem
    type="Active"
    title="{DC>Name}"
  />
</List>

Upvotes: 3

Views: 8060

Answers (1)

Marc
Marc

Reputation: 6190

The following should be placed in your respective controller (but I guess you already have implemented something similar)

onPressDcData: function(oEvent) {
    // The actual Item
    var oItem = oEvent.getSource();
    // The model that is bound to the item
    var oContext = oItem.getBindingContext("DC");
    // A single property from the bound model
    var sName = oContext.getProperty("Name");
}

Hope that helps

Upvotes: 9

Related Questions