Get Selected Item Details

2019-04-11 22:16发布

问题:

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>

回答1:

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



标签: sapui5