使用悬停事件或鼠标悬停扩展sap.ui.core.Icon

时间:2016-12-30 09:54:11

标签: hover sapui5 jquery-hover

我使用悬停事件处理扩展了sap.ui.core.Icon:

    sap.ui.define(function () {
    "use strict";
    return sap.ui.core.Icon.extend("abc.reuseController.HoverIcon", { 
            metadata: {
                events: {
                    "hover" : {}  
                }
            },

//          the hover event handler, it is called when the Button is hovered - no event registration required
            onmouseover : function(evt) {   
                this.fireHover();
            },

//          add nothing, just inherit the ButtonRenderer as is
            renderer: {}            
        });  
});

事件onmouseover永远不会被解雇。我还使用了sap.m.Button和works的扩展名。但我需要这个sap.ui.core.Icon。

我也尝试了this jquery示例,但它根本不起作用。

$("testIcon").hover(function(oEvent){alert("Button" + oEvent.getSource().getId());});

请问,您是否知道为什么没有为sap.ui.core.Icon调用事件处理程序onmouseover?或者你能提出一些其他解决方案吗?

贝娄是我如何将图标添加到我的sap.suite.ui.commons.ChartContainer:

        var oFilterIcon = new HoverIcon({   
                tooltip     : "{i18n>filter}",
                src         : "sap-icon://filter",
                hover       : function(oEvent){alert("Button" + oEvent.getSource().getId());},
            });

        this.byId("idChartContainer").addCustomIcon(oFilterIcon);   

1 个答案:

答案 0 :(得分:1)

这是我的分析:

  1. 您的新自定义悬停控制图标是正确的。如果您将独立使用它,它将正常工作。
  2. 但是,当您使用ChartContainer时,您的图标将转换为sap.m.OverflowToolbarButton,您的自定义控件将无效。
  3. 我查看了Chart Container的源代码,下面是代码:

    sap.suite.ui.commons.ChartContainer.prototype._addButtonToCustomIcons = function(i) {
        var I = i;
        var s = I.getTooltip();
        var b = new sap.m.OverflowToolbarButton({
            icon: I.getSrc(),
            text: s,
            tooltip: s,
            type: sap.m.ButtonType.Transparent,
            width: "3rem",
            press: [{
                icon: I
            }, this._onOverflowToolbarButtonPress.bind(this)]
        });
        this._aCustomIcons.push(b);
    }
    

    因此,您不使用Icon,但会使用其属性。由于这是标准代码,因此不会传递自定义图标的悬停代码。

    一种解决方案是将onmouseover添加到sap.m.OverflowToolbarButton:

    sap.m.OverflowToolbarButton.prototype.onmouseover=function() {
     alert('hey')
    

    };

    然而,这很危险,因为所有OverflowToolbarButton按钮都开始使用此代码,我不会推荐它。

    下一个解决方案是覆盖私有方法:_addButtonToCustomIcons(同样不推荐:()

    sap.suite.ui.commons.ChartContainer.prototype._addButtonToCustomIcons = function(icon) {
                var oIcon = icon;
                var sIconTooltip = oIcon.getTooltip();
                var oButton = new sap.m.OverflowToolbarButton({
                    icon : oIcon.getSrc(),
                    text : sIconTooltip,
                    tooltip : sIconTooltip,
                    type : sap.m.ButtonType.Transparent,
                    width : "3rem",
                    press: [{icon: oIcon}, this._onOverflowToolbarButtonPress.bind(this)]
                });
                this._aCustomIcons.push(oButton);
    
    
                //oButton.onmouseover.
                oButton.onmouseover = function() {
                    this.fireHover();
                }.bind(oIcon);
            };
    

    如果这有助于你,请告诉我。 :)

相关问题