D3.Js可折叠树在文件更新后与旧数据绑定

时间:2016-07-28 05:28:35

标签: d3.js flask

我正在使用以下可折叠树代码来呈现我的数据https://bl.ocks.org/mbostock/4339083。当它第一次从指定文件读取并正确呈现时,在对文件的进一步更新时,它继续显示旧数据。

Json文件的结构如下:

{
 "name": "ArnavG",
 "children": [
  {
   "name": "11th Building",
   "children": [
     {"name": "17:10 - 22:54", "size": 1}
   ]
  },
  {
   "name": "12th Building",
   "children": [
     {"name": "02:11 - 04:19", "size": 1},
     {"name": "03:32 - 19:51", "size": 1}
   ]
  },
  {
   "name": "15th Building",
   "children": [
     {"name": "16:29 - 19:38", "size": 1},
     {"name": "15:08 - 21:20", "size": 1}
   ]
  },
  {
   "name": "16th Building",
   "children": [
     {"name": "01:48 - 02:11", "size": 1},
     {"name": "08:09 - 23:50", "size": 1}
   ]
  },
  {
   "name": "18th Building",
   "children": [
     {"name": "20:58 - 22:35", "size": 1}
   ]
  },
  {
   "name": "19th Building",
   "children": [
     {"name": "23:57 - 23:59", "size": 1}
   ]
  },
  {
   "name": "20th Building",
   "children": [
     {"name": "22:10 - 22:45", "size": 1}
   ]
  }
 ]
}

文件阅读:

d3.json("../static/query1.json", function(error, values) {
              if (error) throw error;

              root = values;
              root.x0 = height / 2;
              root.y0 = 0;

              function collapse(d) {
                if (d.children) {
                  d._children = d.children;
                  d._children.forEach(collapse);
                  d.children = null;
                }
              }

              root.children.forEach(collapse);
              update(root);
            });

此外,上述代码段中的“值”是什么?

0 个答案:

没有答案