我正在扩展一个fiori应用程序,并替换了一个视图并放置了一个弹出窗口。现在我的要求是,当我单击弹出窗口中的关闭按钮时,我想打开一个xmlview。
code.
sap.m.MessageBox.error( "Error Message - some error",
{ icon: sap.m.MessageBox.Icon.ERROR, title: "Confirmation Error", onClose: function (oAction) {
this.router = sap.ui.core.UIComponent.getRouterFor(this);
this.router.navTo("customview"); } } );
有人可以建议我遇到的错误吗?
'navTo' of undefined
manifest.json
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"viewPath": "publicservices.her.myApp.myAppExtension.view",
"controlId": "app",
"controlAggregation": "pages",
"async": true
},
"routes": [{
"pattern": "",
"name": "customView",
"target": "customView"
}
],
"targets": {
"customView": {
"viewName": "customView",
"viewId": "customView"
}
}
}
}
答案 0 :(得分:1)
我想让您检查一下项目以便定义路由器。我在下面添加了一个示例。
希望这会有所帮助。
组件
init: function() {
UIComponent.prototype.init.apply(this, arguments);
this.setModel(models.createDeviceModel(), "device");
// MAKE SURE YOUR ROUTER IS INITIALISED HERE
this.getRouter().initialize();
}
清单1
确保添加了controlId和controlAggregations
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"viewPath": "Test.view",
"controlId": "app",
"controlAggregation": "pages"
},
清单2
"routes": [{
"pattern": "",
"name": "main",
"target": "main"
}, {
"pattern": "side",
"name": "side", // YOU'LL USE THIS NAME TO NAVIGATE IN THE CONTROLLER
"target": "side"
}],
"targets": {
"main": {
"viewName": "Main"
},
"side": {
"viewName": "Side" // ENSURE THIS IS CORRECT (this refers to view: 'Side.view.xml')
}
}
查看
<App id="app"> <!-- ADD THIS ID TO ALL VIEWS -->
<pages> <!-- SHOULD HAVE THE SAME VALUE AS CONTROLID IN THE MANIFEST-->
<Page title="Page 1">
<content>
<Button press="onOpenMessageBox" text="Open" />
</content>
</Page>
</pages>
</App>
控制器
导航到名称为“边”的路线
onOpenMessageBox: function() {
var that = this; // SET VARIABLE THAT TO THIS
sap.m.MessageBox.error("Error Message - some error", {
icon: sap.m.MessageBox.Icon.ERROR,
title: "Confirmation Error",
onClose: function(oAction) {
// CHANGE ALL 'this' TO 'THAT'
// THIS HAS ANOTHER CONTEXT IN THIS FUNCTION
that.oRouter = sap.ui.core.UIComponent.getRouterFor(that);
that.oRouter.navTo("side");
}
});
}