sapui5 - XML 视图的 SapUI5 路由器问题
问题描述
我正在开发一个简单的 UI5 项目,能够了解路由器的工作原理。在这个过程中,我遇到了与路由器事件相关的问题。我有三个 XML 视图,它们的名称分别是 FirstPage、SecondPage 和 ThirdPage。ThirdPage 在其他两个页面中实现,如下代码;
<mvc:XMLView viewName="SapUI5Tutorial.Application.Main.views.ThirdPage.view.ThirdPage"/>
例如 FirstPage.xml
<mvc:View displayBlock="true" controllerName="SapUI5Tutorial.Application.Main.views.FirstPage.controller.FirstPage"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core"
xmlns:l="sap.ui.layout"
xmlns="sap.m" height="100%">
<Page title="First Page" class="sapUiNoContentPadding">
<subHeader>
<Toolbar>
<VBox width="100%" alignItems="Center">
<Button text="Second Page Link" press="handleNavSecondPage"/>
</VBox>
</Toolbar>
</subHeader>
<mvc:XMLView viewName="SapUI5Tutorial.Application.Main.views.ThirdPage.view.ThirdPage"/>
</Page>
当我单击“第二页链接”按钮时,我正在导航到 SecondPage。但是ThirdPage是由于SecondPage里面ThirdPage的Router函数运行了两次
ThirdPage 的控制器;
sap.ui.define([
"sap/ui/core/mvc/Controller",
], function (Controller, FragmentController) {
"use strict";
var base, oRouter;
return Controller.extend("SapUI5Tutorial.Application.Main.views.ThirdPage", {
onInit: function () {
base = this;
base.getView().setModel(oModel);
oRouter = sap.ui.core.UIComponent.getRouterFor(base);
oRouter.getRoute("FirstPage").attachMatched(base.firstPagePatternMatched, base);
oRouter.getRoute("SecondPage").attachMatched(base.secondPagePatternMatched, base);
},
firstPagePatternMatched: function (oEvent) {
console.log(oEvent)
},
secondPagePatternMatched: function (oEvent) {
//Due to the third page is used for inside two other pages (FirstPage and SecondPage) this function is running twice
console.log(oEvent)
}
});
});
如何防止运行 ThirdPage 的 Router 事件两次?谢谢你的帮助
解决方案
推荐阅读
- ace-editor - 在 Ace 编辑器中的 setValue 之后保留光标位置
- android - Retrofit2 调用维基百科 API 没有得到想要的响应
- c++ - #include 之间的关系是什么
和 getch() 方法? - c++ - 什么是“不可检测的手段”,它们如何改变 C/C++ 程序的对象?
- python - 如何在后台找到运行 VBScript 的文件位置?
- apache-spark - 在pyspark中计算大型数据帧的所有行之间的余弦相似度
- node.js - Node.js gRPC 库上的 QUIC 协议
- javascript - 无法在 express 中加载 javascript 文件
- python - 如何解决 toml.decoder.TomlDecodeError: Key group not on a line by itself。(第 1 行第 1 列 ...)调用 streamlit 包时出错?
- assembly - 给定两个内存地址,我可以将数据从一个地址移动到另一个地址,而该数据不会进入寄存器