使用香草GWT的匿名内部类中的奇怪行为
上面的类是GWT组合,让我感到困惑的是,为什么即使分离了TextComposite,该行也会运行?请参阅代码使用香草GWT的匿名内部类中的奇怪行为,gwt,Gwt,上面的类是GWT组合,让我感到困惑的是,为什么即使分离了TextComposite,该行也会运行?请参阅代码 KeyMaster是mousetrap.js的包装器,它的键盘绑定是全局的,这意味着,即使TestComposite被分离,当我按下快捷键时,process方法仍然被执行。因此,我使用isAttached来防止它在合成未显示在DOM中时运行,但是它确实运行了,并且isAttached返回true,有人能解释一下吗?isAttached!=我看得见。isAttached的javadoc说
KeyMaster是mousetrap.js的包装器,它的键盘绑定是全局的,这意味着,即使TestComposite被分离,当我按下快捷键时,process方法仍然被执行。因此,我使用isAttached来防止它在合成未显示在DOM中时运行,但是它确实运行了,并且isAttached返回true,有人能解释一下吗?isAttached!=我看得见。isAttached的javadoc说
public class TestComposite extends Composite{
private String str = "hello";
public TestComposite() {
Keymaster.get().bindShortcuts("alt+up", new Keymaster.KeymasterHandler() {
@Override
public void process(String shortcut) {
if (isAttached()) {
GWT.log("do the job");//why enter here even if TextComposite is detached
}
}
});
}
}
试一试
'Determines whether this widget is currently attached to the browser's
document (i.e., there is an unbroken chain of widgets between this widget
and the underlying browser document).'
TestComposite不在DOM中,而不是不可见的,我编辑了我的帖子,谢谢。
if(isVisible()) {
...
}