gpt4 book ai didi

gwt - GWT 历史中需要什么 History.fireCurrentHistoryState()?

转载 作者:行者123 更新时间:2023-12-01 14:59:13 24 4
gpt4 key购买 nike

您好,我正在开发一个 GWT 样本历史管理应用程序。这是我的 onModuleLoad 代码。

public void onModuleLoad() {
ContentPanel panel = ContentPanel.getInstance();
if(History.getToken()!=null && History.getToken().length()==0)
{
History.newItem("first_page");
}
History.addValueChangeHandler(new HistoryHandler());
RootPanel.get().add(panel);
History.fireCurrentHistoryState();
}

在此我触发了 History.fireCurrentHistoryState();触发当前的历史状态。现在在我的 firstPanel 类中有一个名为 Second Panel 的按钮,在该按钮上触发了历史标记 second_page。

public FirstPanel() {
VerticalPanel panel = new VerticalPanel();
Button button2 = new Button("Second Panel");
button2.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
History.newItem("second_page");
}
});
panel.add(button2);
initWidget(panel);
}

但是这里不需要触发 History.fireCurrentHistoryState() ;再次。只需 histt​​ory.newItem 就可以正常工作。

现在我想知道 History.fireCurrentHistoryState() 仅在模块加载时需要什么?还有为什么在申请中不需要第二次。?

最佳答案

History.fireCurrentHistoryState() 会调用您的历史处理程序,而不会在浏览器历史堆栈中实际插入新的历史项,而 History.newItem(token) 会将新的历史标记插入到历史堆栈。

注意:如果您当前的 token 与新 token 相同(即重新加载同一页面),则浏览器不会将其插入历史堆栈。在这种情况下(当前 token == 新 token )History.fireCurrentHistoryState()History.newItem(currentToken) 具有相同的效果。

关于gwt - GWT 历史中需要什么 History.fireCurrentHistoryState()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6925228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com