[英]Destroying jQuery Flot Graph
以一種清理所有事件處理程序而不會導致內存泄漏的方式銷毀jQuery flot圖的正確方法是什么?
似乎flot留下了一些僵屍(又名Detached Dom Trees)
如果您閱讀了API文檔,那么有一種關閉方法可以為您清理
shutdown()
Cleans up any event handlers Flot has currently registered. This
is used internally.
例如。
var plot = $.plot($("#yourDiv"), options)
plot.shutdown()
對於將來來這里的人來說,現在有一個destroy
函數可以調用shutdown並刪除canvas元素。 由於某種原因,它在API中沒有記錄,但在代碼中可用:
var flot = $("#FlotDiv").data('plot')
if (flot) // If it's destroyed, then data('plot') will be undefined
flot.destroy();
如果要刪除事件處理程序,請嘗試jquery off
方法。
用於清除flot圖。 你可以清空div。
$('#yourFlotDiv').empty();
刪除flot Graph
var placeholder = $("#FlotDiv");
placeholder.unbind(); //Remove a previously-attached event handler from the elements.
placeholder.empty();
如果您希望解除特定事件的綁定,這是要走的路:
$( "#foo").unbind( "click" );
有關詳細信息,請查看此信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.