为什么我的主控制器被调用了两次? [英] Why Is My Main Controller Being Called Twice?
本文介绍了为什么我的主控制器被调用了两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有其他路由都很好,但由于某种原因主控制器被调用了两次.为什么会发生这种情况?
All other routings are fine, but for some reason the main controller is being called twice. Why would this happen?
onInit: function() {
var oRouter = this.getOwnerComponent().getRouter();
oRouter.getRoute("main").attachMatched(this._onRouteMatched, this);
this.getView().setModel(new JSONModel({
Jobs: []
}), "job");
},
这与路由配置有关吗?
"rootView": {
"viewName": "CompleteSurvey.view.Main",
"type": "XML"
},
"routing": {
"routes": [{
"name": "main",
"pattern": "",
"target": ["main"]
}],
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"viewPath": "CompleteSurvey.view",
"controlId": "app",
"controlAggregation": "pages"
},
"targets": {
"main": {
"viewName": "Main"
}
}
}
推荐答案
你的 Main
控制器被创建两次的原因是因为它的视图被创建了两次.
The reason why your Main
controller is created twice is because its view is created twice.
- 您的组件获取 manifest.json 并查看
rootView
以创建指定的视图 ("CompleteSurvey.view.Main"
). - 你的路由器被初始化,看到当前的哈希/模式是
""
,并再次创建相应的视图,即"Main"
视图.
- Your Component fetches manifest.json and looks at the
rootView
to create the assigned view ("CompleteSurvey.view.Main"
). - Your router gets initialized, sees that the current hash / pattern is
""
, and creates the corresponding view which is the"Main"
view again.
当前的最佳做法是拥有一个单独的根视图.您可以为 ""
模式保留 Main
,但避免再次使用相同的视图作为根视图.
The current best practice is to have a separate root view. You can keep the Main
for the ""
pattern, but avoid using the same view again as a root view.
For further references, take a look at the tutorial Navigation and Routing and this answer.
这篇关于为什么我的主控制器被调用了两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文