如何从同一json的树数据读取JSON数据,而不是从其他.JSON文件读取? [英] How to read JSON data from same json for tree layout insteadof reading from other .JSON file?

查看:89
本文介绍了如何从同一json的树数据读取JSON数据,而不是从其他.JSON文件读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从相同的.js文件读取JSON数据,而不是从目前使用的其他.JSON文件中读取它:

  d3.json(network.json,function(error,treeData){
//树布局逻辑在这里

}
/ pre>

而不是这样我们可以从同一个js文件读取数据ang如何使用它来构建树布局

解决方案

解决方案



1.您可以将JSON数据分配给变量名称构建树布局



2.使用一个函数获取 JSON 数据



小提示 1个解决方案



小提琴 2解决方案

  var root = getData(),
nodes = cluster.nodes(root),
links = cluster.links(nodes);


how to read JSON data from same .js file instead of reading it from other .JSON file currently I am using :

d3.json("network.json", function(error, treeData){
   // tree layout logic goes here

}

instead of this can we read data from same js file ang how to use it to build tree layout

解决方案

Solution:

1.you can assign the JSON data to variable name then You can build the tree layout

2.use one function to get the JSON data

Fiddle for 1 solution

Fiddle for 2 solution

    var root = getData(),
    nodes = cluster.nodes(root),
    links = cluster.links(nodes);

这篇关于如何从同一json的树数据读取JSON数据,而不是从其他.JSON文件读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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