Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript D3JS高亮显示包含给定字符串的节点_Javascript_Jquery_Asp.net_D3.js - Fatal编程技术网

Javascript D3JS高亮显示包含给定字符串的节点

Javascript D3JS高亮显示包含给定字符串的节点,javascript,jquery,asp.net,d3.js,Javascript,Jquery,Asp.net,D3.js,我愿意搜索并突出显示包含给定字符串的节点。 为此,我调用set_focus方法 function set_focus(d) { text.style("opacity", function(o) { return isConnected(d.id, o.id) ? 1 : null; }); img.style("opacity", function(o) { return isConnec

我愿意搜索并突出显示包含给定字符串的节点。

为此,我调用set_focus方法

function set_focus(d)
{   
    text.style("opacity", function(o) {
        return isConnected(d.id, o.id) ? 1 : null;
    });

    img.style("opacity", function(o) {
        return isConnected(d.id, o.id) ? 1 : null;
    });

    link.style("opacity", function(o) {
        return o.source.index == d.index || o.target.index == d.index ? 1 : null;
    }); 

}
上述函数有条件地设置元素的不透明度。我想设置相互连接的节点的不透明度。但是我不想干扰那些没有连接的节点的不透明性

如需进一步澄清:

return isConnected(d.id, o.id) ? 1 : null;
如果
isConnected==false,我不想返回不透明度

必需:
返回是否已连接(d.id、o.id)?1:“此处返回当前不透明度值”


发生:
返回未连接(d.id,o.id)?1:“返回零或空”

您可以使用getter获取当前元素的不透明度值:

d3.select(this).style("opacity");
然后,您可以在三元运算符中使用它:

text.style("opacity", function(o) {
    var current =  d3.select(this).style("opacity");
    return isConnected(d.id, o.id) ? 1 : current;
});

谢谢Gerardo,我已经试过你说的了…但是var current=d3.select(this.attr(“不透明”);正在返回null。我需要在创建文本时设置文本的不透明度吗?好的,var current=d3。选择(this).style(“不透明度”);用样式替换attr。。。。非常感谢。