如果当前页面的孩子都不可见,是否可以自动将页面重新路由到第一个孩子?场景是我构建了一系列选项卡式内容区域,我通过Knockout和Pager.js控制路由。我想要的是,如果一个标签内容区域有子标签,则路线应该自动调整以显示第一个孩子是活动的。我无法使用' start'设置该子页面。角色,因为我不能保证第一个孩子永远是一样的。
我创建了一个显示架构的基本小提琴:
<div id="myApp">
<div data-bind="page: { id: 'start', role: 'start' }">
<ul class="nav nav-tabs" data-bind="foreach: $page.children">
<li data-bind="css: {active: isVisible}"><a data-bind="text: $data.val('title'), page-href: $data"></a></li>
</ul>
<div data-bind="page: { id: 'page-one', title: 'Page One' }">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Earum, quae totam illum eaque reiciendis incidunt tempore alias a possimus laboriosam dolorum officia assumenda fugit quo tenetur voluptas recusandae labore culpa.</p>
</div>
<div data-bind="page: { id: 'page-two', title: 'Page Two' }">
<p>Suscipit, quibusdam, ex rerum quae minus ullam esse aliquam non nihil officia! Doloribus expedita veritatis porro quae quos ad ex dolorum minus temporibus facilis. Quia, ipsum officia ullam perferendis minima?</p>
</div>
<div data-bind="page: { id: 'page-three', title: 'Page Three' }">
<p>Tempora, similique laborum quas eos ullam sit consequatur tenetur corrupti quod dolore! Porro, ex, architecto, pariatur perspiciatis a itaque velit illo autem rem nihil error minima minus alias nostrum enim?</p>
</div>
<div data-bind="page: { id: 'page-four', title: 'Page Four' }">
<p>Doloribus, dolore, eligendi, vitae vero fugiat accusantium ex error eum qui enim molestiae labore dignissimos aperiam quis suscipit placeat unde consequatur ipsum eos in sed dolorem officia consequuntur nihil mollitia.</p>
</div>
<div data-bind="page: { id: 'page-five', title: 'Page Five' }">
<p>Dolor, quo quis voluptates suscipit velit harum totam officiis quisquam quia perspiciatis amet aspernatur tempore magnam. Eos, in, vel similique temporibus dolores animi neque delectus sunt blanditiis voluptatem nisi cum!</p>
</div>
</div>
结果应该是它会自动路由到路径ID为&#39; page-one&#39;的子页面。