我在 YUI 脚本中使用 AlloyUI 组件,并试图将 aui-tabview (Pills) 与 aui-pagination 结合起来,以便单击每个选项卡(pill) 更新每个选项卡的内容/节点列表中的分页。例如,如果 tab-2 的节点列表中有 7 个项目,那么我应该得到 7 个分页按钮,tab-3 的 6 个项目应该显示 6 个分页按钮,等等。我无法让这两个组件集成。任何帮助将不胜感激。
这是我的代码:
<div id="myTab">
<ul class="nav nav-pills">
<li class="active"><a href="#view-all">View all</a></li>
<li><a href="#beauty">Beauty</a></li>
<li><a href="#days-out">Days out</a></li>
<li><a href="#holidays">Holidays</a></li>
</ul>
<div class="products tab-content">
<div id="beauty" class="tab-pane">
<div>some content</div>
<div>some more content</div>
<div>more content</div>
<div>a few words</div>
</div>
<div id="days-out" class="tab-pane">
<div>some content</div>
<div>some more content</div>
<div>more content</div>
<div>a few words</div>
</div>
<div id="holidays" class="tab-pane">
<div>some content</div>
<div>some more content</div>
<div>more content</div>
<div>a few words</div>
</div>
</div>
</div>
<script>
YUI({
}).use('node', 'node-base', 'event', 'transition', 'anim', 'aui-tabview', 'aui-pagination', function(Y) {
new Y.TabView(
{
srcNode: '#myTab',
type: 'pills'
}
).render();
Y.one(".nav.nav-pills").delegate('click', function(e) {
var id = Y.one(e.currentTarget);
var href = id.get('href');
var arr = href.split("#");
var target = arr[1];
var pages = Y.all('#' +target + " > div");
var total_rows = pages._nodes.length;
Y.log(total_rows);
new Y.Pagination(
{
page: 1,
total: total_rows,
boundingBox: '#pagination',
circular: false,
contentBox: '#pagination .pagination-content',
on: {
changeRequest: function(event) {
var instance = this,
current = event.currentTarget,
state = event.state,
lastState = event.lastState;
if (lastState) {
pages.item(lastState.page - 1).setStyle('display', 'none');
}
pages.item(state.page - 1).setStyle('display', 'block');
}
},
after: {
changeRequest: function(event) {
// goto top
a = new Y.Anim(
{
node: 'body',
to: {scrollTop: 0},
duration: 0.4,
easing: Y.Easing.easeOut
}
);
a.run();
}
},
strings: {
next: '»',
prev: '«'
}
}
).render();
}, 'a');
}
);
</script>