作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
关闭。这个问题不符合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);
handleEvent1
函数可能如下所示:
handleEvent1 : function(channel, event, data) {
var customData = data.customData
}
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/
我是一名优秀的程序员,十分优秀!