我在SAP WebIDE中有问题,无法在UI5应用程序上显示XS OData服务

时间:2019-04-29 04:03:19

标签: javascript sapui5 sap hana sap-web-ide

我正在创建一个应用,以向用户显示应用的推荐结果,但无法在应用上显示。

错误显示 显示属性在我的基本控制器文件中未定义

错误代码为getOwnerComponent(“ myComp”)。getTargets()。display(to)位于appview.controller.js文件(控制器文件)中

注意:如果我对组件容器使用方法1,则可以初始化路由器,但由于找不到组件ID,错误是未定义的目标。

但是,如果我对组件容器使用方法2,则可以getOwnerComponent,但由于无法初始化路由器而显示未定义。

有什么想法吗?

appview.controller.js

 handlePressOpenMenu: function(oEvent) {
      var oButton = oEvent.getSource();
      // create menu only once
      if (!this._menu) {
        this._menu = sap.ui.xmlfragment("apps.html.fragment.view_menu", this);
        this.getView().addDependent(this._menu);
      }
      var eDock = sap.ui.core.Popup.Dock;
      this._menu.open(this._bKeyboard, oButton, eDock.BeginTop, eDock.BeginBottom, oButton);
    },
    handleMenuItemPress: function(oEvent) {
      if (oEvent.getParameter("item").getSubmenu()) {
        return;
      }
      var to = oEvent.getParameter("item").data("to");
      if (to) {
        this.getOwnerComponent("myComp").getTargets().display(to);
      }

    },

manifest.json

"routing": {
            "config": {
                "routerClass": "sap.m.routing.Router",
                "viewType": "XML",
                "async": true,
                "viewPath": "apps.html",
                "controlAggregation": "pages",
                "controlId": "idAppControl",
                "transition": "slide"
            },
            "routes": [{
                "name": "appview",
                "pattern": "",
                "target": ["appview"]
            }],
            "targets": {
                "appview": {
                   "clearAggregation": true,
                    "viewName": "appview"
                },
                 "xsodata.collaborative": {
                  "clearAggregation": true,
                  "viewName": "xsodata.collaborative"
                },
                 "xsodata.contentbased": {
                  "clearAggregation": true,
                  "viewName": "xsodata.contentbased"
                },
                "xsjs.apl_recommendation": {
                  "clearAggregation": true,
                  "viewName": "xsjs.apl_recommendation"
                },
                   "xsjs.pal_apriori": {
                  "clearAggregation": true,
                  "viewName": "xsjs.pal_apriori"

                }
}
}
}
}
}

component.js

    return UIComponent.extend("apps.html.Component", {

        metadata: {
            manifest: "json"
        },

        /**
         * The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
         * @public
         * @override
         */
        init: function () {
            // call the base component's init function
            sap.ui.core.UIComponent.prototype.init.apply(this, arguments);


            // set the device model
            this.setModel(models.createDeviceModel(), "device");

            // initialise router
             this.getRouter().initialise();




        }
    });
});

index.html方法1

sap.ui.getCore().attachInit(function() {

                new sap.m.Shell({

                    app: new sap.ui.core.ComponentContainer({
                        id:"myComp",
                        height : "100%",
                        name : "movielens.html",
                        propagateModel:true
                    }).placeAt("content")
                });

index html方法2

sap.ui.getCore().attachInit(function() {
                var oComp =  sap.ui.getCore().createComponent({
                        name:"apps.html",
                        id:"myComp",
                        height:"100%",
                        propagateModel:true
                    });
                new sap.m.Shell({

                    app: new sap.ui.core.ComponentContainer({
                    component:oComp
                    }).placeAt("content")
                });

执行结果应该是基于用户选择的推荐显示。

0 个答案:

没有答案