【问题标题】:DASH Javascript client-side call back precedes Python triggered call_backDASH Javascript 客户端回调先于 Python 触发的回调
【发布时间】:2021-09-14 20:00:18
【问题描述】:

我有一个破折号应用程序,其中一个打印按钮使用客户端回调在 Javascript 中执行窗口打印。我希望 Print 按钮在触发 Javascipt 窗口打印之前触发 python 回调,以便我可以隐藏布局功能并防止其显示。无论我尝试什么,javascript 打印窗口都会首先打开,并且只有在关闭该窗口时才会触发其他 python 回调。有解决办法吗?谢谢

dbc.Button('Print Record', id='printing', outline=True, className="d-print-none",
                                   n_clicks=0,)

@app.callback(
    [,
        Output("printing", "n_clicks"),
    ],

    [Input("printing", "n_clicks")],
)
def toggle_sidebarnclick(n):
    "code toggles a layout feature so it doesn't appear on the screen"

    return n

app.clientside_callback(
    """
    function(clicks) {
        if (clicks > 0) {
          try {
  document.execCommand('print', false, null);
}
catch(e) {
  window.print();
}
        }
        return 
    }
    """,
    Output('hidden-content', 'children'),
    Input('printing', 'n_clicks')
)



【问题讨论】:

    标签: javascript plotly-dash client-side


    【解决方案1】:

    解决方法很简单:

    {
    setTimeout(window.print, 1000)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-04
      • 1970-01-01
      • 2019-05-22
      • 1970-01-01
      • 2011-10-09
      • 2020-06-12
      相关资源
      最近更新 更多