V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
shinession
V2EX  ›  Python

请教大佬 js 和 Python 鼠标单击和双击 callback 问题

  •  
  •   shinession · 2022-10-02 15:08:35 +08:00 · 2003 次点击
    这是一个创建于 543 天前的主题,其中的信息可能已经有所发展或是发生改变。
    下面是 dash—tabulator JS 里鼠标单击和双击 callback 设置代码,

    window.myNamespace = Object.assign({}, window.myNamespace, {
    tabulator: {
    cellClick: function (e, cell, table) {
    // console.log(cell)
    table.props.setProps({"cellClick" : [cell._cell.column.field, cell._cell.row.data]})
    },
    cellDblClick: function (e, cell, table) {
    // console.log(cell)
    table.props.setProps({"cellDblClick" : [cell._cell.column.field, cell._cell.row.data]})
    }
    }
    });

    python 里代码如下
    @app.callback(
    [Output("app-content", "children")],
    [Input('tabulator', 'cellClick'), Input('tabulator', 'cellDblClick')],
    prevent_initial_call=True,
    )
    def function(cell_cllick,cell_dbl_click):
    pass

    问题是鼠标单击优先级高于双击,如果我同时设置点击表格事件,单击肯定触发,双击设置就无效了。
    如果 js 里单击事件加上延迟,哪怕 1ms 延迟,python 里单击 callback 又无法生效,请教大佬们是如何解决优先级问题的
    3 条回复    2022-10-03 15:53:15 +08:00
    Torpedo
        1
    Torpedo  
       2022-10-03 11:38:40 +08:00
    可以监听 mousedown 和 up ,然后自己判断是否是单机或者双击。
    或者单击直接加个几百 ms 的锁,如果这期间没有双击,就认为是单击
    shinession
        2
    shinession  
    OP
       2022-10-03 12:19:25 +08:00
    @Torpedo 大佬指点下如何加锁并且 python 里 callback 有 Input ,我在 JS 里加 sleep(500)之类的总是会破坏 Input
    Torpedo
        3
    Torpedo  
       2022-10-03 15:53:15 +08:00
    @shinession const clickFlagObj={lastClick:''}

    cellClick 的时候设置一下上面的变量,然后 dbClick 的时候读一下上面你设置的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1029 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:32 · PVG 03:32 · LAX 12:32 · JFK 15:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.