【问题标题】:Sencha Touch: Button handler called twice for single click - why?Sencha Touch:按钮处理程序为单击调用两次 - 为什么?
【发布时间】:2011-06-23 16:09:13
【问题描述】:

我的按钮处理程序被调用了两次 - 一次用于 mousedown/touchstart,第二次用于 mouseup/touchend。

这发生在我的 iPhone 设备和我的 Chrome 浏览器中。

使用 ST 1.1

我没有找到任何关于这个问题的参考,这似乎表明我的环境中的某些东西是错误的,但是我没有东西可以检查了......

在 Chrome DevTools 中检查传递给处理程序的事件对象,我可以看到它们都是模拟的“tap”事件,第一个来自“mousedown”,第二个来自“mouseup”。

有什么想法吗?

编辑:

我发现当我向Ext.EventManager.onDocumentReady 添加一个调用(即使是一个空的处理程序)时会发生这种情况。

如果我删除此调用,我只会按预期获得对“mouseup”的点击。

如果我用Ext.onReady 替换它,它就可以工作!!! 这真是令人困惑,因为一个是另一个的别名......

代码复制:

<!DOCTYPE html>
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <script src="resources/Sencha/sencha-touch-debug.js" type="text/javascript"></script>
    <link href="resources/Sencha/sencha-touch.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
        MyPanel = Ext.extend(Ext.Panel, {
            fullscreen: true,

            initComponent: function() {
                this.items = [{
                    xtype: 'button',
                    text: 'Login',
                    handler: this.myHandler,
                    scope: this
                }];

                MyPanel.superclass.initComponent.apply(this, arguments);
            },

            myHandler: function(b, e) {
                console.log(e.event.type);
            }

        });

        Ext.EventManager.onDocumentReady(function() {

        });

        Ext.onReady(function() {
            new MyPanel();
        });
    </script>
    </head>
    <body></body>
</html>

【问题讨论】:

  • 你能提供一些示例代码吗?
  • 或者示例的实时链接也可以使用-
  • 添加重现代码+导致根因
  • 嗨。你找到解决方案了吗?
  • @kalyanipuvvada 我不记得找到原因了,但我认为使用“Ext.onReady”而不是“Ext.EventManager.onDocumentReady”的解决方法对我来说已经足够了。

标签: sencha-touch


【解决方案1】:

我在未修饰的链接节点上遇到过这个问题。我设法通过在A 节点上吃touchend 事件来解决它:

document.addEventListener('touchend', function(e) {
  e.preventDefault() if e.target.localName == 'a')
}, true);

这不完全是您的问题,但您的问题很可能是类似的,由 touch 和 click 事件发送到小部件引起。 Here 是我用来向控制台发送垃圾邮件的一种方法,尽可能多地发送所有事件(即原始 DOM 事件,而不是 Ext 事件)。它对于解决此类低级问题很有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    相关资源
    最近更新 更多