2017-11-23 8 views
1

다른 모든 라우팅은 문제가 없지만 어떤 이유로 메인 컨트롤러가 두 번 호출됩니다. 왜 이런 일이 일어날까요?SAPUI5 - 주 컨트롤러가 두 번 호출되는 이유는 무엇입니까?

onInit: function() { 
     var oRouter = this.getOwnerComponent().getRouter(); 
     oRouter.getRoute("main").attachMatched(this._onRouteMatched, this); 
     this.getView().setModel(new JSONModel({ 
      Jobs: [] 
     }), "job"); 

    }, 

라우팅 구성까지입니까? 해당 뷰가 두 번 만들어지기 때문에

"routes": [{ 
      "name": "main", 
      "pattern": "", 
      "titleTarget": "", 
      "greedy": false, 
      "target": ["main"] 
     }, { 

"config": { 
      "routerClass": "sap.m.routing.Router", 
      "viewType": "XML", 
      "viewPath": "CompleteSurvey.view", 
      "controlId": "app", 
      "controlAggregation": "pages", 
      "bypassed": { 
       "target": ["main"] 
      }, 
      "viewLevel": 1 
     }, 
     "targets": { 
      "main": { 
       "viewType": "XML", 
       "transition": "slide", 
       "clearAggregation": true, 
       "viewName": "Main", 
       "viewLevel": null 
      }, 
+0

앱 설명자에서 'sap.ui5/rootView'에 할당 한보기는 무엇입니까? – boghyon

+0

"rootView": { \t \t \t "viewName과": "CompleteSurvey.view.Main" \t \t \t "유형": "XML" –

+0

주요, 즉 ... –

답변

2

당신의 Main 컨트롤러가 두 번 생성하는 이유는 다음과 같다.

  1. 귀하의 구성 요소 manifest.json을을 가져 와서 할당보기 ("CompleteSurvey.view.Main"를) 만들 수 rootView 본다.
  2. 라우터가 초기화되고 현재 해시/패턴이 ""임을 확인하고 다시 "Main"보기 인 해당보기를 만듭니다.

현재 가장 좋은 방법은 별도의 루트보기를 사용하는 것입니다. 은 "" 패턴으로 유지할 수 있지만 동일한보기를 다시 루트보기로 사용하지 마십시오.

+1

추가 참조를 들어 봐 튜토리얼과 [answer] (https://github.com/SAP/openui5/issues/1746#issuecomment)에서 [Enable Routing] (https://openui5.hana.ondemand.com/#/topic/cf3c57c89ef0491793d1ce327ab4f9b2) -346442770). – boghyon