gpt4 book ai didi

durandal - 加载应用程序时在 Durandal 路由器中动态添加/删除路由

转载 作者:行者123 更新时间:2023-12-01 01:10:04 24 4
gpt4 key购买 nike

我需要帮助在 Durandal 路由器中动态添加/删除路由。我想要的是在用户登录后,我将能够根据登录用户的类型添加或删除特定路线。

我试图从 visibleRoutes/allRoutes 数组中添加/删除路由......但从淘汰赛库中获得绑定(bind)异常......

我希望这将是常见的情况......但仍然找不到任何解决方案......请帮助我解决这个问题。

谢谢。
瓦西姆

发表评论:

我尝试使用此功能来动态隐藏/显示路线...并且类似地尝试从 allRoutes[] 添加/删除路线...但随后在淘汰赛出价时出现异常

showHideRoute: function (url,show) {

var routeFounded = false;
var theRoute = null;
$(allRoutes()).each(function (route) {

if (url === this.url) {
routeFounded = true;
var rt = this;
theRoute = rt;
return false;
}
});

if (routeFounded)
{
if (show)
{
visibleRoutes.push(theRoute);
}
else
{
visibleRoutes.remove(theRoute);
}
}
}

最佳答案

在杜兰达尔 2.0.

您可以枚举路线以找到您希望显示/隐藏的路线。

然后改变:nav属性的值

然后运行 ​​buildNavigationModel();

这是一个例子:

// see if we need to show/hide 'flickr' in the routes
for (var index in router.routes) {
var route = router.routes[index];
if (route.route == 'flickr') {
if (vm.UserDetail().ShowFlickr) { // got from ajax call
// show the route
route.nav = true; // or 1 or 2 or 3 or 4; to have it at a specific order
} else if (route.nav != false) {
route.nav = false;
}
router.buildNavigationModel();
break;
}
}

关于durandal - 加载应用程序时在 Durandal 路由器中动态添加/删除路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15881357/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com