How to handle the itemPress of sap.m.Table?

后端 未结 5 1134
南方客
南方客 2020-12-03 15:56

I\'ve written an XML view. Inside it there is a table:

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 16:38

    Another problem in OP's code is that itemPress is used on the level of Table instead of the level of ListItemBase. This will indeed fire click events (if type="Active" is set for the ListItemBase element, as explained in other answers here). BUT: The context of the events will not allow to derive the clicked row in the list! So you get an event, but you will not be able to tell from which item it came.

    Here is what needs to be changed to identify the clicked row in OP's example, using ColumnListItem as an example for ListItemBase:

    Instead of...

... use this:


        
        ...
        
    
        
    

To derive the model path of the clicked row you can now use code like this:

onItemPressed: function (oEvt) {
    var sModelPath = oEvt.getSource().getBindingContext('myModelName').getPath();
    var sDiD = this.getView().getModel("myModelName").getProperty(sModelPath + "/myModelFieldName");
}

You can also add a customData node within the CustomListItem that holds row specific information and access it's key value pairs in the event handler through something like this:

var aCustomData = oEvt.getSource().getCustomData();

But again:
Both approaches will only work if onItemPressed is called on ListItemBase / ColumnListItem level!

提交回复
热议问题