关闭 gwt 中的选项卡之一后选项卡索引出现问题
我正在使用 装饰标签面板。我已经实现了选项卡的关闭选项。现在我的问题是,当我关闭一个选项卡并尝试在另一个选项卡中添加一些数据时,它采用了错误的索引。
例如:我有 4 个选项卡,关闭第三个选项卡。我打开第四个选项卡并尝试在那里添加一些内容,但它的索引显示为 3 而不是 4,因为只有 3 个。
如何重置程序中的选项卡索引,或者任何可以读取正确索引的解决方案标签与删除之前一样吗?
这是我添加新选项卡和关闭事件的地方。
HorizontalPanel horizontalPanel = new HorizontalPanel();
Image image = new Image();
Label label = new Label("New Report: " + k);
label.setWordWrap(false);
horizontalPanel.add(label);
horizontalPanel.add(image);
image.setUrl("images/1305803163_close.png");
tabpanel.add(newTab[k], horizontalPanel);
tabindexx[k] = k;
image.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
tabpanel.remove(tabpanel.getTabBar().getSelectedTab());
}
});
在代码的某些部分中,我正在像这样访问选项卡索引
int selectedtab = tabpanel.getTabBar().getSelectedTab();
当然,这将根据特定时刻存在的选项卡数量返回一个索引,所以我需要将它们存储在某个地方,否则我必须重置选项卡索引我关闭后。
I am developing a application in GWT using the decorated tab panel. I have implemented a close option for the tabs. Now my problem is that when I close one tab and try to add some data in the other tab it is taking the wrong index.
For example: I have 4 tabs and close the third one. I open 4th tab and try to add something there, but its index is showing as 3 instead of 4 as there are only 3.
How can I reset the tab index in the program, or else any solution where I can read the correct index of tab as it was before removing it?
This is where i am adding the new tab and the close event.
HorizontalPanel horizontalPanel = new HorizontalPanel();
Image image = new Image();
Label label = new Label("New Report: " + k);
label.setWordWrap(false);
horizontalPanel.add(label);
horizontalPanel.add(image);
image.setUrl("images/1305803163_close.png");
tabpanel.add(newTab[k], horizontalPanel);
tabindexx[k] = k;
image.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
tabpanel.remove(tabpanel.getTabBar().getSelectedTab());
}
});
and in some part of the code I am accessing the tab index like this
int selectedtab = tabpanel.getTabBar().getSelectedTab();
Of course this will return an index based on the number of tabs present at that particular moment, so I need to store them somewhere or else I have to reset the tab index after I close.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
之所以会发生这种情况,是因为索引号是当前选项卡集的索引。 (如果其中一个关闭,显然会影响其他)。
我现在对 GWT 有点生疏,但我相信删除或选择选项卡的唯一方法是使用索引。
一种解决方案可能是管理代码中的选项卡代表列表(某些选项卡标识符),并在代码中发生删除时在该列表中执行镜像删除。然后您可以在删除后查找要更新的选项卡的新索引并获取正确的索引。 (选项卡标识符可以像在任何删除之前启动时选项卡的原始索引一样简单)
That will happen because the index number is the index for the current set of tabs. (if one closes, it obviously impacts the others).
I am a little rusty with GWT now, but i believe the only way to remove or select tabs is using index.
One solution could be to manage a List of tab representatives (some tab identifier) in your code, and do a mirror remove in that list when a delete occurs in your code. Then you can lookup the new index of the tab that you want to update after the delete and get the right index. (Tab identifier can be as simple as the original index of the tab when you started before any deletes)