由于控制器实例化,SAPUI5发布后订阅问题

由于控制器实例化,SAPUI5发布后订阅问题,sapui5,Sapui5,ProjectInfo:在WebIDE中使用主/详细Fiori模板构建应用程序 我在我的详细信息页面上有一个列表,当选中时,每个项目都应该链接到应用程序详细信息部分的新视图 Detail.controller.js: onInspectionSelect : function(oEvent) { var oBindingContext = oEvent.getParameter( "listItem").getBindingContext();

ProjectInfo:在WebIDE中使用主/详细Fiori模板构建应用程序

我在我的详细信息页面上有一个列表,当选中时,每个项目都应该链接到应用程序详细信息部分的新视图

Detail.controller.js:

onInspectionSelect : function(oEvent) {
         var oBindingContext = oEvent.getParameter(
         "listItem").getBindingContext();
         this.getEventBus().publish("InspectionDetails", "Context", { context : oBindingContext} );

    this.getRouter().myNavToWithoutHash({
       currentView : this.getView(),
       targetViewName : "DOHMH.view.InspectionDetails",
       targetViewType : "XML",
       transition : "slide"
}); },
    onInit : function() {

    var bus = sap.ui.getCore().getEventBus();
    bus.subscribe("InspectionDetails", "Context", this._inspection, this);
},

_inspection : function (channelId, eventId, data) {

    if (data && data.context) {
        this.getView().setBindingContext(data.context);
        var sEntityPath = data.context.getPath();
        this.bindView(sEntityPath);
    }
},
My InspectionDetails.controller.js:

onInspectionSelect : function(oEvent) {
         var oBindingContext = oEvent.getParameter(
         "listItem").getBindingContext();
         this.getEventBus().publish("InspectionDetails", "Context", { context : oBindingContext} );

    this.getRouter().myNavToWithoutHash({
       currentView : this.getView(),
       targetViewName : "DOHMH.view.InspectionDetails",
       targetViewType : "XML",
       transition : "slide"
}); },
    onInit : function() {

    var bus = sap.ui.getCore().getEventBus();
    bus.subscribe("InspectionDetails", "Context", this._inspection, this);
},

_inspection : function (channelId, eventId, data) {

    if (data && data.context) {
        this.getView().setBindingContext(data.context);
        var sEntityPath = data.context.getPath();
        this.bindView(sEntityPath);
    }
},
第一次从“详细信息”页面选择列表项时,由于选择事件触发发布时未订阅InspectionDetails.controller,该选项不起作用

不幸的是,我不知道如何正确构建它,也不知道如何提前实例化控制器以避免错过第一个调用

要在详细信息中实例化控制器,控制器不起作用: jQuery.sap.require(“DOHMH.view.InspectionDetails”); (返回404),因为它不知道是获取InspectionDetails.view.xml还是InspectionDetails.controller.js

已解决-感谢所有帮助

还找到了视频解决方案
为什么这么复杂?将InspectionDetails视图附加到特定路由,并在回调中设置其绑定上下文。当然,您必须将路由扩展到InspectionDetails,因为您需要传递ID或任何要显示的实体。

我会将subscribe调用放在一个了解项目列表和项目详细视图的组件上。协调两者

或者,更简单的方法是不使用事件,而是使用命名模型。单击列表中的项目时,将模型的数据设置为“currentItem”,然后绑定到“currentItem>x”的详细视图字段将自动更新

您可以将路由框架和所描述的模型技术结合起来,在视图之间创建无缝导航