我有一个类似下面的代码。
<p:tabView value="#{bean.entityList}" id="tabView" var="item">
<p:tab title="#{item.name}">
.
.
.
</p:tab>
</p:tabView>我想访问选项卡的索引,就像访问数据表的rowIndexVar一样。如何获取制表符索引?
发布于 2017-06-01 13:55:29
有一个非常可怕的解决办法,我不推荐,但这是我能想到的最好的办法。它涉及到使用一点Javascript来跟踪选项卡计数,并在每个选项卡中使用更多的Javascript来生成需要选项卡索引的HTML。
在页面的<head>中,初始化制表符计数器;
<head>
<script>
// Global tab counter
tabCount = -1;
</script>
</head>然后,当您绘制每个选项卡时,递增计数器。在选项卡中,无论何时需要选项卡索引,都可以编写一个小脚本来生成包含索引的HTML。例如:
<p:tabView value="#{bean.entityList}" id="tabView" var="item">
<p:tab title="#{item.name}">
<script>
// Increment the tab counter
tabCount++;
</script>
<!-- Now the tab content -->
The index of this tab is:
<script>
document.write(tabCount);
</script>
</p:tab>
</p:tabView>正如我所说的,它很可怕,每当我看到它时都会让我退缩,但它是有效的。
https://stackoverflow.com/questions/10027833
复制相似问题