티스토리 뷰
SAPUI5에 EventBus를 찾아보면 이렇게 나옵니다.
It is recommended to use the EventBus only when there is no other option to communicate between different instances, e.g. native UI5 events.(어쩔 수 없을 경우에만 사용)
여러분이 EventBus까지 알아본거면 이 방법을 사용할 수 밖에 없는 경우라고 생각합니다. 간단하게 설명하면 EventBus는 주로 다른 View 사이에서 Event를 캐치해야 할 때 사용됩니다. 사용하는 방법은 간단합니다.
Event를 발생시키는 View
1 2 3 4 | <mvc:View controllerName="com.edu.orderFirst.controller.View2" xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m"> <Text text="View2 Area" /> <Button text="View2" press=".onPress" /> </mvc:View> | cs |
Event를 발생시키는 Controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | sap.ui.define([ "sap/ui/core/mvc/Controller", 'sap/ui/export/library', 'sap/ui/export/Spreadsheet' ], function (Controller, exportLibrary, Spreadsheet) { "use strict"; var EdmType = exportLibrary.EdmType; return Controller.extend("com.edu.orderFirst.controller.View2", { onInit: function () { }, onPress : function (sChannelId, sEventId, sData) { sap.ui.getCore().getEventBus().publish( "SomeChannel", "SomeEvent", {text: "An event has occurred in View2"} ); } }); }); | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | sap.ui.define([ "sap/ui/core/mvc/Controller", "sap/m/MessageBox" ], function (Controller, MessageBox) { "use strict"; return Controller.extend("com.edu.orderFirst.controller.View3", { onInit: function () { sap.ui.getCore().getEventBus().subscribe( "SomeChannel", "SomeEvent", this.onPress2 , this ); }, onPress2 : function (sChannelId, sEventId, sData) { MessageBox.success(sData.text + ". But The event is triggered in View3 "); //console.log(sData.text); } }); }); | cs |
Event를 받는 부분에는 미리 subscribe을 설정해 주셔야 합니다. Event가 발생시키는 곳에 설정하셨던(publish했던 곳) Channel Id와 Event Id를 똑같이 설정해 줍니다.(첫번째, 두번째 parameter) 세번째 parameter로 실행시킬 함수를 지정해 줍니다. 이 때 주의하셔야 할 것은 직접함수(parameter 자리에 function() {} 으로 넣는 방법)를 넣지 않고 위에 처럼 외부의 함수를 정의하고 호출하는 경우 함수 이름 뒤에 ()를 붙이지 않습니다. 네번째 paramter로 this를 설정해 주시면 됩니다.
실행화면
처음에는 헷갈릴 수 있는데 막상 해보면 간단하게 처리됩니다. SCP webide에 작성한 예제 파일을 첨부했습니다.
참고 URL
https://openui5.hana.ondemand.com/api/sap.ui.core.EventBus#constructor
'SAPUI5' 카테고리의 다른 글
DatePicker 년이나 월만 선택(only 세팅값만 가지고) (0) | 2021.01.14 |
---|---|
SelectBox나 ComboBox에 바인딩한 데이터가 전부 안나오는 경우 (0) | 2020.12.05 |
Step 19: Reuse Dialogs (0) | 2018.12.19 |
Step 18: Icons (0) | 2018.12.19 |
Step 17: Fragment Callbacks (0) | 2018.12.19 |
- Total
- Today
- Yesterday
- array
- app init
- App Initialization
- hanadb
- 소프트웨어 공급자
- What Happens When an App Is Started
- 소프트웨어
- 자바스크립트
- 세금계산서
- 거래처품목 등록
- ie
- fiori
- 토킹클래스
- sap
- window.open
- 개발자
- 홈택스
- Reds and Blues
- loading order
- FormData
- 개발자 세금계산서
- sapui5
- model.cds
- javascript
- 홈택스 리뉴얼
- 토킹클래스 1+단계
- component.js
- ORT
- 오알티
- 피오리
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |