- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个应用程序,并希望显示一个 2 层菜单,这两层始终可用。杜兰达尔 2.0 introduced their new router ,它支持“子路由器”,可以更轻松地进行深层链接。
我的问题 - 我可以永久加载我的“子”导航路线吗(并且在父项不事件时呈现子菜单),还是“子路由器”设计旨在延迟加载它们以在要评估深层链接时对其进行评估?
Durandal 示例显示 主导航注册一个 splat 路由,然后当该 View 模型被加载/激活时,子路由被注册。
例如:在 Durandal 2.0 提供的示例中,mian nev 注册在 shell.js
router.map([
{ route: ['', 'home'], moduleId: 'hello/index', title: 'Validation test', nav: true },
{ route: 'knockout-samples*details', moduleId: 'ko/index', title: 'Knockout Samples', nav: true, hash: '#knockout-samples' }
]).buildNavigationModel()
.activate();
ko/index.js
View 模型然后注册 child (在
activate()
上)
var childRouter = router.createChildRouter()
.makeRelative({
moduleId:'ko',
fromParent:true
}).map([
{ route: '', moduleId: 'helloWorld/index', title: 'Hello World', type: 'intro' },
{ route: 'helloWorld', moduleId: 'helloWorld/index', title: 'Hello World', type: 'intro', nav: true},
{ route: 'clickCounter', moduleId: 'clickCounter/index', title: 'Click Counter', type: 'intro', nav: true}
]).buildNavigationModel();
var routes = [
{ route: ['', 'home'],
moduleId: 'hello/index',
title: 'Validation test',
nav: true },
{ route: 'knockout-samples*details',
moduleId: 'ko/index',
moduleRootId: 'ko', // Custom property to make child routes easier
title: 'Knockout Samples',
nav: true,
hash: '#knockout-samples',
childRoutes: [
{ route: '', moduleId: 'helloWorld/index', title: 'Hello World', type: 'intro' },
{ route: 'helloWorld', moduleId: 'helloWorld/index', title: 'Hello World', type: 'intro', nav: true},
{ route: 'clickCounter', moduleId: 'clickCounter/index', title: 'Click Counter', type: 'intro', nav: true}
]}
])
// Load routes router.map(routes.navRoutes).buildNavigationModel().mapUnknownRoutes(function(instruction)
{
logger.logError('No Route Found', instruction.fragment, 'main', true);
});
// Try load child routes...
$.each(routes.navRoutes, function(index, parentRoute) {
if (!parentRoute.childRoutes) {
return;
}
var childRouter = router.createChildRouter()
.makeRelative({
moduleId: parentRoute.moduleRootId,
fromParent: true // also tried false + non-splat routes...
}).map(parentRoute.childRoutes).buildNavigationModel();
});
最佳答案
我希望我能帮到你一点。
您可以永久加载“子”路由器吗?
据我所知你不能(或者说没有简单的方法可以实现)。子路由器旨在为特定 View 提供子路由功能 - 您可以将它们视为 Durandal View 中的 Durandal 导航。如果我们检查 Durandal 页面上的示例代码,我们可以很容易地看到子路由生命周期与给定的 View 相关联。更重要的是,如果我们检查创建子路由的函数的代码,我们将看到它创建了新的路由器并且只存储对父路由器的引用 - 父路由器(在大多数情况下是主路由器)没有对其子路由器的引用
router.createChildRouter = function() {
var childRouter = createRouter();
childRouter.parent = router;
return childRouter;
};
var routes = [
{
route: ['', 'home'],
moduleId: 'viewmodels/home',
title: 'Validation test',
nav: true
},
{
route: 'knockout-samples',
moduleId: 'viewmodels/ko/index',
moduleRootId: 'viewmodels/ko', // Custom property to make child routes easier
title: 'Knockout Samples',
nav: true,
hash: '#knockout-samples',
childRoutes: [
{ route: 'simpleList', moduleId: 'simpleList', title: 'SimpleList', nav: true, hash : 'simpleList' },
{ route: 'clickCounter', moduleId: 'clickCounter', title: 'Click Counter', nav: true, hash : 'clickCounter' }
]
}
];
$.each(routes, function(index, route) {
if (route.childRoutes === undefined)
return
$.each(route.childRoutes, function(index, childRoute) {
childRoute.route = route.route + '/' + childRoute.route;
childRoute.moduleId = route.moduleRootId + '/' + childRoute.moduleId;
childRoute.title = route.title + '/' + childRoute.title;
childRoute.hash = route.hash + '/' + childRoute.hash;
childRoute.parent = route.moduleRootId;
});
routes = routes.concat(route.childRoutes);
});
return router.map(routes)
.buildNavigationModel()
.activate();
<div class="btn-group" data-bind="foreach: router.navigationModel">
<!-- ko if: $data.childRoutes === undefined && $data.parent === undefined -->
<a data-bind="css: { active: isActive }, attr: { href: hash }, text: title" class="btn btn-info" href="#"/>
<!-- /ko -->
<!-- ko if: $data.childRoutes !== undefined -->
<div class="btn-group btn-info">
<a data-bind="css: { active: isActive }, attr: { href: hash }, text: title" class="btn btn-info" href="#"/>
<button class="btn btn-info dropdown-toggle" data-toggle="dropdown">
<span class="caret"/>
</button>
<ul class="dropdown-menu" data-bind="foreach: childRoutes">
<a data-bind="css: { active: isActive }, attr: { href: hash }, text: title" class="btn btn-info" href="#"/>
</ul>
</div>
<!-- /ko -->
</div>
关于Durandal 2.0 - 用于嵌套菜单的子路由器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19483651/
Nuget 说我已经为我正在检查的项目安装了 Durandal Transitions 包,但是 ~/Scripts/durandal/transitions仅包含默认过渡 entrance.js 其
每次我读到有关 Javascript 的新内容时,我都会阅读有关 Durandal 和 Aurelia 的内容。我在很多博客上听到开发人员要求从 Durandal 升级到 Aurelia 或类似的版本
在我基于 HotTowel 的项目中,我使用 Durandal 1.1.1 进行路由。 我有一个登录路由,如果用户未登录,我想激活该路由。 我的路线配置如下: var routes = [ {
每次我读到有关 Javascript 的新内容时,我都会阅读有关 Durandal 和 Aurelia 的内容。我在很多博客上听到开发人员要求从 Durandal 升级到 Aurelia 或类似的版本
Durandal route 星号的用途是什么?这是来自 the Docs 的示例: route:'knockout-samples*details' 编辑:使用 Durandal 2.0 最佳答案
Durandal 路由中星号的用途是什么?这是来自 the Docs 的示例: route:'knockout-samples*details' 编辑:使用 Durandal 2.0 最佳答案 您引用
我的 Durandal 路由配置如下。 var routes = [ ....... More Routes Here..... { url: 'login', moduleId: '
我正在使用 Durandal 2.0。我有一个搜索 View ,想将所选项目传递到详细信息 View 。我知道如何传递 Id,但由于在这种情况下搜索具有整个对象,因此我想在导航时传递对象。我以为我可以
我搜索如何在撰写数据绑定(bind)上停用转换, 因为我在 chrome 上的内容 html 并不美观而且小错误。 因为我在过渡时有一个滚动水平打印,并且在移动鼠标后消失了。 内容在 iFrame 中
在我的 shell 中,我按照以下方式设置了路线: router.map([ { route: '', title: 'Search', moduleId: 'viewmode
我正在尝试使用 John Papa 的 HotTowel 模板实现 SPA。我可以做多少级的 ko compose 有限制吗? 在它调用的 shell.html 中 在我的事件 View 中,我尝试
我需要帮助在 Durandal 路由器中动态添加/删除路由。我想要的是在用户登录后,我将能够根据登录用户的类型添加或删除特定路线。 我试图从 visibleRoutes/allRoutes 数组中添加
我正在看的文章是Durandal Router . 下 mapAuto ,它说我们可以在 url #/customers/1 中传递 splat 参数.和 activate viewmodel 中的函
我正在查看这些路由信息对象结构的文档,但没有找到任何内容。由于 Durandal 使用其他 JS 库,我不确定它属于什么(也许是 sammy?)。 我面临两个问题:问题 #1 我想在路线信息中使用一个
我有一个现有的 Durandal.js 应用程序,它利用了所有 ES5 功能,但我想将它升级到新的 Aurelia 平台。什么是正确的升级路径?最简单的升级方式是什么?是否有包含升级路径的文档? 最佳
我正在开发 Hottowel 项目,并更新到 Durandal 2.0。我已经关注了Converting from 1.x to 2.0 guide ,但我仍然有一些问题: 1.加载router插件总
在我看来......这种方式的初始路线是通过以下方式定义的: { route: '', moduleId: 'viewmodels/customers', title: 'customers', na
我想知道是否有人在 Durandal.js 上遇到过类似的问题。 我收到间歇性的“未找到 View 。搜索”错误,很难复制,因为只是偶尔发生。 当 createView 函数无法定位 View 时,它
当您在 SPA 代码中的某处遇到脚本错误时,整个应用程序变得完全没有响应并且您无法导航到任何其他页面(视图)。似乎 durandal 只是卡住了! (唯一的出路是点击刷新再次启动SPA) 在 Du
两者有什么区别,什么时候适合使用它们?我已经看过文档,但还没有完全弄清楚。 最佳答案 这两个事件都是 Durandal 生命周期回调的一部分。 activate() 允许新对象执行自定义激活逻辑。 (
我是一名优秀的程序员,十分优秀!