gpt4 book ai didi

events - 如何在 SAPUI5 中使用 getEventBus 方法

转载 作者:行者123 更新时间:2023-12-03 18:19:34 24 4
gpt4 key购买 nike

关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

4年前关闭。




Improve this question




我想了解 getEventBus() .有人可以提供教程或最佳示例,我们可以在哪里以及如何实现 getEventBus() .

最佳答案

我提供了一个例子来回答另一个问题 here .

简而言之,您可以调用sap.ui.getCore().getEventBus()访问 EventBus 实例。由于它来自核心,因此在所有 View / Controller 中都是相同的。 EventBus 为您提供发布/订阅功能。例如,这使您可以在 Controller A 中发布事件并通知订阅的 Controller B。一个简单的示例主要来自我的其他答案:

订阅 EventBus:

var eventBus = sap.ui.getCore().getEventBus();
eventBus.subscribe("channel1", "event1", this.handleEvent1, this);

当然,您可以根据需要命名您的 channel 和事件。第三个参数表示函数,将在发布事件的情况下调用。最后一个参数是范围,“this”将指向给定函数。

您的 handleEvent1函数可能如下所示:
handleEvent1 : function(channel, event, data) {
var customData = data.customData
}

将事件发布到 EventBus:
var customData = {}  // anything you eventually want to pass
var eventBus = sap.ui.getCore().getEventBus();

eventBus.publish("channel1", "event1",
{
customData: customData
}
);

如果您对此有更多疑问,请告诉我,以便我扩展它。

关于events - 如何在 SAPUI5 中使用 getEventBus 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25382988/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com