如何获取d3中的变量属性 [英] How to get variable attribute in d3

查看:412
本文介绍了如何获取d3中的变量属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用d3返回变量的特定属性?

How do I return a specific attribute of a variable using d3?

例如,我想通过鼠标悬停选择一个元素,并将选择传递给一个函数,但只有当元素 id 是一个特定的名称。

For example, I want to select an element by mouseover, and pass on the selection to a function, but only if the element's id is a particular name.

这样的东西?

d3.select("body").on("mouseover", function(){ 
    if (d3.select(this).attr("id") == "correct") {
        enableInteraction(d3.select(this));
    }
});


推荐答案

选择 this ,然后使用常用函数访问属性。

Yes. Select this and then use the usual functions to access properties.

这篇关于如何获取d3中的变量属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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