This.domNode is null

I am trying to use jquery to load a dojo chart. I am using this code. However, in the second click in the first button, I get this error. The same thing happens if I click on the first button, click on the second and click on the first again. This problem is driving me crazy.

demo here

enter image description here

<script type="text/javascript"> $(document).ready(function () { $('.lista_').click(function () { $.get('index1.php', function (data) { dojo.addOnLoad(function () { require(["dojo/_base/xhr", "dojo/parser", "dojo/dom"], function (xhr, parser, dom) { var um = []; dijit.registry.filter(function (w) { //problem here, maybe this code destroy something that should not be destroyed if (dojo.indexOf(um)) { w.destroyRecursive(); } }); $('#paginas').html(data); dojo.parser.parse(dojo.byId('paginas')); }); }); }); }); }); </script> 
+7
source share
1 answer

It looks like you are trying to delete the old chart before inserting / disassembling the new one, but I don't think this is happening. This can cause Dojo to fix various errors.

 dijit.registry.filter(function (w) { //problem here, maybe this code destroy something that should not be destroyed if (dojo.indexOf(um)) { w.destroyRecursive(); } }); 

I'm not sure what you are doing here. The filter function returns an array of the widget for which the callback returns true. In addition, dojo.indexOf used to search for an element in an array (I'm not sure what kind of black magic you do there: P).

I think (if I understood your intentions), you'd better:

 dijit.registry.findWidgets(dojo.byId("paginas")).forEach(function(w) { w.destroy(); }); 

This will destroy the widget inside #paginas before pasting and parsing recently loaded HTML.

Edit:. When you click the second button and the chart is deleted, the <style> also deleted. That's why you see artifacts from the div tooltip because it is no longer hidden by CSS. You can solve this problem by importing the claro.css file into the main file, namely:

 <style type="text/css"> @import "http://ajax.googleapis.com/ajax/libs/dojo/1.7/dijit/themes/claro/claro.css"; </style> 

in the main file, not in the HTML loaded with jquery (index1.php).

+3
source

All Articles