首页 > 解决方案 > SAP UI5 BlockLayout - 如何设置可点击块?

问题描述

我最近开始学习 SAP UI5 并很快陷入困境。我的登录页面是围绕BlockLayout 控件构建的,该控件包含多个具有各种类别的块。这些块中的每一个都应该是可点击的——在新闻事件之后,用户被重定向到具有更多数据的子页面。

在 Fiori 设计指南中,我在 BlockLayout 部分找到了此信息

也可以让可点击的块具有自己的悬停和按下状态。

这正是我所需要的,但是,我没有找到更详细的解释。有人可以建议我吗?如何在 BlockLayout 控件中设置这些可点击的块?我应该使用 Press 事件扩展控件还是有更直接的方法?

谢谢

标签: sapui5

解决方案


好吧,已经 3 年了,但我有解决方案:我们可以使用以下方法将浏览器事件附加到确定的元素

oElement.attachBrowserEvent("click", function() {
    alert()
})

但是我制作了这段代码来获取一个数组,其中包含所有元素,其中包括在其 id 中确定的字符串,这个 id 由 sapUi5 创建。

var oElements = this.getView().findElements(true); // Get all elements from the view
var array = [];
// search trhoug the elements of the view a element that the ID includes "cell" (from the original ID: __celln)
oElements.forEach(oElement => {
    if (oElement.sId.includes("cell")) {
        array.push(oElement); // And pushes them into the array
    }
})
// go trhoug all elements of the array attaching the click event
array.forEach(cell => {
    cell.attachBrowserEvent("click", function() {
        alert()
    })
})

推荐阅读