Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用香草GWT的匿名内部类中的奇怪行为_Gwt - Fatal编程技术网

使用香草GWT的匿名内部类中的奇怪行为

使用香草GWT的匿名内部类中的奇怪行为,gwt,Gwt,上面的类是GWT组合,让我感到困惑的是,为什么即使分离了TextComposite,该行也会运行?请参阅代码 KeyMaster是mousetrap.js的包装器,它的键盘绑定是全局的,这意味着,即使TestComposite被分离,当我按下快捷键时,process方法仍然被执行。因此,我使用isAttached来防止它在合成未显示在DOM中时运行,但是它确实运行了,并且isAttached返回true,有人能解释一下吗?isAttached!=我看得见。isAttached的javadoc说

上面的类是GWT组合,让我感到困惑的是,为什么即使分离了TextComposite,该行也会运行?请参阅代码


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()) {
  ...
}