SAPUI5:动态添加路由会引发错误

时间:2017-02-26 19:29:39

标签: sapui5

我想动态添加一些路由到路由器。但它会引发以下错误:

  

必须为每条路线指定名称    - EventProvider sap.ui.core.routing.Router A @ sap-ui-core.js:88

我使用的代码如下:

for (var i = 0; i < aRoutes.length; i++) {
    var _name = aRoutes[i].name,
        _pattern = sPatternPrefix + aRoutes[i].pattern,
        _target = aRoutes[i].target;
    var oRoute = new sap.ui.core.routing.Route(oRouter, {
        name: _name,
        pattern: _pattern,
        target: _target
    }); 
    oRouter.addRoute(oRoute, oParent);
}

可能是什么原因,虽然所有name参数都有一个有效的字符串?

创建Route时不会抛出错误,但是当我想使用addRoute函数时,它会被抛出。

1 个答案:

答案 0 :(得分:1)

您不需要创建position。只需使用<form name="form" id="form_action" method="post" action=""> <input name="email" type="email" id="email" placeholder="email@school.com" required> <input name="name" type="text" id="name" placeholder="name" required> <button type="submit" id="submit" onclick="check_email()">Submit!</button> </form> <script type="text/javascript"> function check_email(){ var email = document.getElementById("email").value; if(email == ''){ alert('Enter email'); return false; } if(email.indexOf('school1.com') !== -1) { document.getElementById("form_action").action ="school1.com"; document.getElementById('form_action').submit(); } else { document.getElementById("form_action").action ="school2.com"; document.getElementById('form_action').submit(); } } </script> 中描述的oConfig对象即可。因此改变你的代码:

Route