微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – this.domNode为null

我正在尝试使用 jquery来加载dojo图表.我正在使用此代码.但是在第二次单击时,在第一个按钮中我收到此错误.如果我单击第一个按钮,单击第二个按钮并再次单击第一个按钮,也会出现同样的情况.这个问题让我抓狂.

demo 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>

解决方法

看起来你试图在插入/解析新图表之前删除旧图表,但我不认为这种情况正在发生.这可能会导致Dojo阻止各种错误.
dijit.registry.filter(function (w) { //problem here,maybe this code destroy something that should not be destroyed
    if (dojo.indexOf(um)) {
        w.destroyRecursive();
    }
});

我不确定你在这做什么. filter函数将返回一个widget的数组,其回调返回true.另外,dojo.indexOf用于搜索数组中的元素(我不确定你在那里用它做什么样的黑魔法:P).

我想(如果我理解你的意图),你应该做:

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

在插入和解析新获取的HTML之前,这将破坏#paginas中的窗口小部件.

编辑:当您单击第二个按钮,并删除图表时,< style>标签也被删除了.这就是为什么你看到工具提示div中的工件,因为它不再被CSS隐藏.你可以通过在主文件中导入claro.css来解决这个问题,即把它:

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

在主文件的头文件而不是在您使用jquery(index1.PHP)加载的HTML中.

原文地址:https://www.jb51.cc/js/156708.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐