如果当前页面的子项都不可见,是否可以自动将页面重新路由到第一个子项?场景是我正在构建一系列选项卡式内容区域,并通过 Knockout 和 Pager.js 控制路由。我想要的是,如果一个选项卡内容区域有子选项卡,则路由应自动调整以显示第一个子选项卡处于活动状态。我不能只将那个子页面设置为“开始”角色,因为我不能保证第一个孩子总是一样的。
我创建了一个显示架构的基本小提琴:
<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 为“page-one”的子页面。