如何根据条件过滤返回函数: 例如我的链接的json数据
"links": [
{
"pie": "false",
"source": 1,
"target": 0
},
{
"pie": "true",
"source": 2,
"target": 1
},
{
"pie": "true",
"source": 3,
"target": 1
},
{
"pie": "false",
"source": 4,
"target": 2
},
{
"pie": "true",
"source": 4,
"target": 3
}
]
所以根据饼“TRUE”或“FALSE”,我必须在链接上添加标记。 代码:
var path = d3.select('.pitch').selectAll("path")
.data(force.links())
.enter().append("svg:path")
// .attr("class", function(d) { return "link " + d.type; })
.attr("class", "link")
.attr("marker-end",function(d){ if(d.pie) return "url(#BLUE)"});// condition
但它对我不起作用。请帮帮我。在此先感谢
答案 0 :(得分:0)
nodes.filter(function(d){return d.pie === 'true'};
我认为可行的东西