0

我有这样的 JSON 数据:

{
 "name": "OSS Applications",
 "children": [
  {
     "name": "ELITE 3E",
     "children": [
      {"name": "Elite 3E Mobile Gateway"},
      {"name": "Elite 3E Mobile Website"},
      {"name": "Elite 3E Mobile Application"}

     ]
    },
    {
     "name": "WESTLAW DOC & FORM BUILDER",
     "children": [
      {"name": "Cobalt Website WFB"},
      {"name": "Cobalt Static Content WFB"},
      {"name": "Cobalt Search WFA"},
      {"name": "Cobalt Forms Assembly WFB"},
      {"name": "Cobalt Foldering WFB"}
     ]
    },
    {
     "name": "FINDLAW.COM",
     "children": [
      {"name": "Findlaw-Infirmation"},
      {"name": "Findlaw-hippocms"},
      {"name": "Findlaw-Lawyers Directory"},
      {"name": "Findlaw-ProfileUpdate"},
      {"name": "Findlaw-Pview"},
    {"name": "Findlaw-RCMS"},
    {"name": "Findlaw-public-channel"}
     ]
    }
 ]
}

我想为应用程序“ELITE 3E”、“WESTLAW DOC & FORM BUILDER”和“FINDLAW.com”添加一个 url 链接。我怎么做?我正在尝试复制可折叠的缩进树。mbostock 的块 #1093025

4

2 回答 2

3

您可以使用SVG 链接来实现此目的。您需要做的就是在a要充当链接的元素周围添加一个元素,例如

svg.append("a")
   .attr("xlink:href", function(d) { return d.url; })
   .append("circle")
   //etc

要使链接在新窗口中打开,请将target属性设置为_blank

svg.append("a")
   .attr("xlink:href", function(d) { return d.url; })
   .attr("target", "_blank")
于 2013-10-17T09:36:48.830 回答
0

我以前添加链接如下,你可以添加attr onclick。

<text x="7" y="20" style="font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;font-size:12px;color:white;fill:white;" zIndex="1">
    <tspan onclick="location.href="http://target.url.com"" style="cursor: pointer;" x="7">URL TEXT</tspan>
</text>

而另一种方式,你可以绑定点击事件来实现它。

svg.selectAll('.add-url-node')
   .on('click',function(d){
       location.href = 'target.url.com';
   });
于 2013-10-17T09:52:41.047 回答