我试图从我的数据库 starterkit 在 durandal 2 中创建子路由但没有成功。
虽然我成功地用静态内容渲染它,如下所示:
define(['plugins/router', 'knockout'], function (router, ko) {
var childRouter = router.createChildRouter()
.makeRelative({
moduleId: 'sectionGroups',
fromParent: true
}).map([
{ route: ['', 'child1'], moduleId: 'pages/child1', title: 'child1', nav: true },
{ route: 'child2: moduleId: 'pages/child2', title: 'child2', nav: true },
{ route: 'child3', moduleId: 'pages/child3', title: 'child3', nav: true }
]).buildNavigationModel();
return {
router: childRouter
};
});
但是我一直无法从数据库中动态输出菜单。我做错了什么吗?请在下面查看我的代码
define(['plugins/router', 'knockout','services/oasisManager', 'services/logger'], function (router, ko, om, logger) {
var pageRoutes = getPageRoutes();
var childRouter = router.createChildRouter()
.makeRelative({
moduleId: 'sectionGroups',
fromParent: true
})
.map(pageRoutes)
.buildNavigationModel();
function getPageRoutes() {
var pageRoutes = [];
om.getOasis(134).done(function() {
ko.utils.arrayForEach(om.activeOasis.PageRoutes, function(item) {
var nav = true;
if (item.Route == '') {
nav = false;
}
pageRoutes.push({
route: item.Route,
moduleId: item.ModuleId,
title: item.Title,
nav: nav
});
});
});
return pageRoutes;
}
return {
router: childRouter
};
});
Html 看起来几乎一样。请帮忙
<div class="container-fluid knockout-samples">
<div class="row-fluid">
<div class="span2 well">
<ul class="nav nav-list">
<li class="nav-header">Basic Examples</li>
<!--ko foreach: router.navigationModel-->
<li data-bind="css: { active: isActive }">
<a data-bind="attr: { href: hash }, text: title"></a>
</li>
<!--/ko-->
</ul>
</div>
<div class="span10">
<!--ko router: { transition:'entrance', cacheViews:true }--><!--/ko-->
</div>
</div>