如何将 mouseenter 事件侦听器附加到 sap.m.StandardListItem

How to attach a mouseenter event listener to sap.m.StandardListItem?

本文关键字:sap StandardListItem 侦听器 mouseenter 事件      更新时间:2023-09-26

我需要在拖动standardListItem时检索一些附加到的数据。我正在使用可拖动的jQuery-UI处理拖动。我做了以下工作:

var oItemTemplate = new sap.m.StandardListItem();
oItemTemplate .bindProperty("title", "ListModel>oLabel");
oItemTemplate .data("usefulListData","ListModel>EdmType");
oItemTemplate .addStyleClass("Draggable");
oItemTemplate .setType(sap.m.ListType.Active);
oItemTemplate .attachPress(function( ){
console.log(this.data("usefulListData"));
console.log("item pressed");
});

但是数据检索仅在单击StandardListItem时有效,在拖动元素时不起作用。因此,这个想法是在mouseenter附加检索的数据,如何附加事件侦听器mouseenter事件。

您可以将浏览器事件附加到任何控件,如下所示。

oItemTemplate.attachBrowserEvent("mouseenter", function(oEvent) {
    //get your model and do whatever you want:
    oModel = sap.ui.getCore().getModel();
});

一个名为 attachBrowserEvent 的函数可用于从 sap.ui.core.Control 继承的每个对象:https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.core.Control.html#attachBrowserEvent

使用该函数,您基本上可以绑定到浏览器提供的任何本机事件。

BR克里斯