折叠/展开 sap.ui.commons.Panel 的事件?

问题描述 投票:0回答:3

我正在开发的这个

SAPUI5
应用程序使用一个
sap.ui.commons.Panel
控件,上面有一些按钮。现在我必须在用户折叠面板时隐藏这些按钮并在展开时显示它们。我尝试使用
getCollapsed()
方法但没有效果。我基本上要寻找的是面板的
collapse
事件,默认情况下不可用。

有人帮忙吗?

sapui5
3个回答
1
投票

嗯,似乎确实没有面板控件的事件处理程序......

作为解决方法,您可以在面板托盘中添加自己的展开/折叠切换按钮,单击该按钮后您可以获取 getCollapsed() 状态并相应地显示/隐藏其他按钮


1
投票

您可以使用 sap.m.Panel https://openui5.hana.ondemand.com/docs/api/symbols/sap.m.Panel.html#event:expand

具有扩展属性,您可以使用

setExpanded(true) ; 

展开面板并让控件保持其状态而无需跟踪它。

我敢肯定,自从您提出问题以来,这一切都发生了变化,并且这个答案与 1.24.2 相关


0
投票

也许这里唯一的解决方案是用您自己的按钮替换默认的折叠图标,并将

press
事件附加到它。喜欢:

1. Declare a `Panel` with `showCollapseIcon` set to false.

    var oPanel = new sap.ui.commons.Panel({                    
        showCollapseIcon: false
    });
2. Add your own button. I prefer a `lite` button.

    var oCollapseButton = new sap.ui.commons.Button({
        icon: '<your icon>',
        lite: true,
        press: function (e) {            
            if (!oPanel.getCollapsed()) {
                //If not collapsed
                oPanel.setCollapsed(true);
                //Code to hide panel buttons
                //(and toggle collapse button image if needed) after this
            } else {
                //If already collapsed
                oPanel.setCollapsed(false);
                //Code to show panel buttons
                //(and toggle collapse button image if needed) after this
            }
        }
    });    
    oPanel.addButton(oCollapseButton);

P.S:您可能还想为自定义折叠按钮添加一些样式和对齐方式。为此,您可以在将按钮添加到面板之前将

CSS3
类添加到按钮中,例如:

    oCollapseButton.addStyleClass('<your class>');
© www.soinside.com 2019 - 2024. All rights reserved.