D3js可折叠树抛出错误请求 [英] D3js collapsible tree throwing bad request

查看:77
本文介绍了D3js可折叠树抛出错误请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用d3js可折叠树状网格显示节点,当我在plunker中运行代码时,出现了奇怪的400错误请求错误.

I am using the d3js collapsible tree grid to display the nodes and when I run the code in plunker I am getting a weird 400 bad request error.

我已经替换了获取json的代码,并直接对json进行了硬编码,如下所示:

I have replaced the code which fetches the json and hard coded the json directly like below:

var treeData ={"user_id":0,"name":"Root Node","children":[{"user_id":0,"name":"Flossie Hickman","children":[....]}]};

    // Calculate total nodes, max label length
    var totalNodes = 0;
    var maxLabelLength = 0;
    // variables for drag/drop
    var selectedNode = null;
    var draggingNode = null;
    // panning variables
    var panSpeed = 200;
    var panBoundary = 20; // Within 20px from edges will pan when dragging.
    // Misc. variables
    var i = 0;
    var duration = 750;
    var root;

链接到Plunker

能不能让我知道我要去哪里错了.

Can you please let me know where I am going wrong.

推荐答案

您的代码在控制台中未显示任何错误,以下是要证明的图像:

Your code doesn't show any error in the console, here is an image to proof:

不过,什么也不会出现.原因很简单:您正在调用脚本...

Still, nothing will show up. The reason is simple: you are calling your script...

<script src="dndTree.js"></script>

...在<body>之前,您具有以下div:

...before the <body>, where you have this div:

<div id="tree-container"></div>

哪个是用于创建svg的div:

Which is the div used to create the svg:

var baseSvg = d3.select("#tree-container").append("svg")

所以,这是正确的顺序:

So, this is the correct order:

<body>
    <div id="tree-container"></div>
    <script src="dndTree.js"></script>
</body>

作为一种好习惯,请在正文底部引用您的脚本.

As a good practice, reference your script at the bottom of the body.

这是工作正常的人(我强调工作"): http://plnkr .co/edit/2aLPBuEXN9f6Tlwekdg5?p = preview

Here is the working plunker (and I emphasise "working"): http://plnkr.co/edit/2aLPBuEXN9f6Tlwekdg5?p=preview

这篇关于D3js可折叠树抛出错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆