【发布时间】:2016-05-09 11:57:08
【问题描述】:
我有一个应用程序,当将 csv 数据拖到图形选项卡时,数据将显示为 jquery 对话框扩展内的图形。一切正常。如果我单击关闭按钮,对话框将按预期关闭。但是,使用 chart.js 构建的图形并没有被破坏。就像我在不刷新页面的情况下再次将数据拖放到图形选项卡一样,对话框扩展将打开并构建旧图形。现在,一旦单击关闭按钮,我想销毁 jquery 对话框中的所有 div、画布、图形。我该怎么做?下面是我的代码?
$("#graph_container").dialog("open")
.dialog({
height: height,
title: data1 + " " + "(1990 January to 2008 December)",
width: width,
resizable: true,
responsive: true,
droppable: true,
close: function(ev, ui) {
graph_myLine.destroy();
$(this).remove();
}
})
.dialogExtend({
"titlebar": 'transparent',
"closable": true,
"minimizable": true,
"minimizeLocation": "right",
"icons": {
"close": "ui-icon-circle-close",
"minimize": "ui-icon-circle-minus",
"restore": "ui-icon-circle-triangle-n"
},
open: function (event, ui) {
$('#graph_container').css('overflow', 'hidden'); //this line does the actual hiding
}
});
如果我运行上面的代码,在按下关闭按钮后,如果我再次将数据拖放到图形选项卡,销毁功能在 chart.js 中不起作用。该图仍然存在。它显示错误为 Uncaught TypeError: Cannot read property 'toDataURL' of null 它在下面的代码行中引发错误
$("#graph_container").droppable({
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
accept: ":not(.ui-sortable-helper)",
drop: function (event, ui) {
HoldOn.open();
//alert(ui.draggable.text());
// $("#info").html("dropped!");
canvas = document.getElementById('canvas');
if (canvas.toDataURL() !== document.getElementById('blank').toDataURL())
【问题讨论】:
-
你的关闭函数在哪里?
-
抱歉,格式不正确。现在它更新了。可以看到关闭功能。
-
调用 $(this).empty();在删除之前
-
$("#graph_container").html('');
-
@Anoop 和 sinto:是的,我尝试添加。但 UncaughtTypeError 仍然存在。
标签: javascript jquery chart.js jquery-dialog