使用参数进行路由 - 未捕获patternMatched事件

时间:2018-02-16 21:03:42

标签: sapui5

我正在使用Web IDE处理UI5应用程序,并且我创建了一个视图,我需要根据从上一个视图接收的参数来绑定数据。但patternMatched事件未触发。

的manifest.json

"routing": {
  "config": {
    "routerClass": "sap.m.routing.Router",
    "viewType": "XML",
    "viewPath": "oomsdisplay.pso.com.view",
    "controlId": "app",
    "controlAggregation": "pages",
    "bypassed": {
      "target": ["notFound"]
    },
    "async": true
  },
  "routes": [{
    "pattern": "",
    "name": "worklist",
    "target": ["worklist"]
  }, {
    "pattern": "ZISOHSet/{objectId}",
    "name": "object",
     "target": ["object"]
  }, {
    "pattern": "ZISOHSet/{objectId}",
    "name": "payobject",
    "target": ["payobject"]
  }],
  "targets": {
    "worklist": {
      "viewName": "Worklist",
      "viewId": "worklist",
      "viewLevel": 1
    },
    "object": {
      "viewName": "Object",
      "viewId": "object",
      "viewLevel": 2
    },
    "objectNotFound": {
      "viewName": "ObjectNotFound",
      "viewId": "objectNotFound"
    },
    "notFound": {
      "viewName": "NotFound",
      "viewId": "notFound"
    },
    "payobject": {
      "viewName": "PayObject",
      "viewId": "payobject",
      "viewLevel": 2
    }
  }
}

Component.js

init: function() {
  UIComponent.prototype.init.apply(this, arguments);
  // ...
  this.getRouter().initialize(); // create the views based on the url/hash
},

现在,我创建了一个视图。当我按下视图上的按钮时,我的第二个视图即PayObject将被调用。这是按下按钮的代码:

fViewPayment: function(oEvent) {
  this.getRouter().getTargets().display("payobject", {
    objectId: "MyParameterhere"
  });
},

现在,这是我的PayObejct视图的init处理程序,它具有对象匹配处理程序。但它没有用。

onInit: function() {
  // ...
  var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
  oRouter.getRoute("payobject").attachPatternMatched(this._onObjectMatched, this);
},

_onObjectMatched: function(oEvent) { // this event handler is not firing
  var sObjectId = oEvent.getParameter("arguments").objectId;
  sap.m.MessageBox.show(sObjectId);
  // ...
},

3 个答案:

答案 0 :(得分:3)

如果您有两条具有相同模式的路由,则只会在路由器中匹配第一条路径。

{
   "pattern": "ZISOHSet/{objectId}",
   "name": "object",
   "target": ["object"]
}, {
   "pattern": "ZISOHSet/{objectId}",
   "name": "payobject",
   "target": ["payobject"]
}

所以在这种情况下"对象"我会匹配吗更改其中一条路线的模式,然后重试。

此外,在导航时使用navTo():

this.getRouter().navTo("payobject", {
  objectId: "MyParameterhere"
});

答案 1 :(得分:1)

而不是使用

getTargets()。显示

使用路由器对象中的方法navTo

https://sapui5.hana.ondemand.com/#/api/sap.ui.core.routing.Router/overview

答案 2 :(得分:1)

你必须使用相同模式的路线:"对象"和" payobject",我会尝试删除一个并再次检查。