navTo仅适用于一页

时间:2016-01-08 15:47:51

标签: sapui5

我的控制器文件中有以下功能:

handleNavTo : function (oEvent){
        var page = oEvent.getSource().data("navToPage");
        var router = sap.ui.core.UIComponent.getRouterFor(this);
        router.navTo(page);
    }

所以我不必为每个链接写一个新函数,我在XML视图中使用数据属性来传入我想要导航到的页面,如下所示:

<StandardTile 
    title="{i18n>tileEmployees}" 
     press="handleNavTo" 
     data:navToPage="employees"
     icon="sap-icon://employee"/>
 <StandardTile 
     title="{i18n>tileProducts}" 
     press="handleNavTo" 
     data:navToPage="products" 
     icon="sap-icon://product"/>

我在manifest.json文件中配置了路由:

"routing": {
  "config": {
    "routerClass": "sap.m.routing.Router",
    "viewType": "XML",
    "viewPath": "testApp.view",
    "controlId": "app",
    "controlAggregation": "pages",
    "transition": "slide",
    "bypassed": {
      "target": "notFound"
    }
  },
  "routes": [
    {
      "pattern": "",
      "name": "appHome",
      "target": "home"
    },
    {
      "pattern": "products",
      "name:": "products",
      "target": "products"
    },
    {
      "pattern": "employees",
      "name": "employees",
      "target": "employees"
    }
  ],
  "targets": {
    "home": {
      "viewName": "Home",
      "viewLevel": 1
    },
    "notFound": {
      "viewName": "NotFound",
      "transition": "flip"
    },
    "products": {
      "viewPath": "testApp.view.products",
      "viewName": "ProductsSplitView",
      "viewType": "JS",
      "viewLevel": 2
    },
    "employees": {
      "viewPath": "testApp.view.employees",
      "viewName": "EmployeesSplitView",
      "viewType": "JS",
      "viewLevel": 2
    }
  }

我的问题是单击瓷砖仅适用于Employees页面。我知道产品页面的路由配置正确,因为我可以在地址栏中输入网址,然后会显示页面:mydomain.com/#/products

我没有错误,它似乎默默地失败了。正确调用data属性值,如果控制器函数中的console.log(page)得到正确的值,那么这就是难以理解的。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

我猜它没有按名称找到路线,因为路线配置中有拼写错误:"name:": "products",应为"name": "products",