【发布时间】:2020-07-29 03:14:00
【问题描述】:
我正在尝试复制模式内特定 IFrame 元素中的内容,以避免不必要的 DB 调用。我正在通过 Python 调用客户端回调(请参阅 here),它返回我想在我的模式中复制的特定 IFrame 元素的索引。
这里是 Python 代码的 sn-p,它切换我的模式并跟踪要复制的最近点击图形的索引:
@app.callback(
[Output('my-modal', 'is_open'),
Output('modal-clone', 'children')],
[Input(f'button{k}', 'n_clicks_timestamp') for k in range(20)] +
[State('my-modal', 'is_open')])
def toggle_modal(*data):
clicks, is_open = data[:20], data[20]
modal_display = not is_open if any(clicks) else is_open
clicked = clicks.index(max(clicks))
return [modal_display, clicked]
app.clientside_callback(
ClientsideFunction(namespace='clientside', function_name='clone_figure'),
Output('modal-test', 'children'),
[Input('modal-clone', 'children'), Input('modal-figure', 'id')]
)
还有以下 Javascript:
window.dash_clientside = Object.assign({}, window.dash_clientside, {
clientside: {
clone_figure: function(clone_from, clone_to) {
source = document.getElementById(clone_from);
console.log(document.getElementById(clone_to))
console.log(document.getElementById(clone_to).contentDocument);
clone = document.getElementById(clone_to);
// set attributes of clone here using attributes from source
return null
}
}
});
现在,从我的console.log() 语句中,我注意到以下内容(请注意,屏幕截图中的modal-clone 对应于我的示例中的modal-figure):
contentDocument 在这两个日志语句之间如何变化?任何见解将不胜感激,我很难过。
【问题讨论】: