【问题标题】:Setting an id issue in d3在 d3 中设置 id 问题
【发布时间】:2012-10-22 17:00:22
【问题描述】:

这就是我正在做的事情:

selection = canvas.selectAll("circle").data(mydata)

            selection.enter().append("circle")

            selection
                .attr("id", function(d, i){ var result = i+''; return result; })

简而言之,我试图将每个元素的 id 设置为其索引的字符串表示形式。

但是,当我稍后尝试使用 d3.select("#1") 或使用数字变量 i 并转到 d3.select("#" + i.toString()) 来访问该特定元素时,似乎没有任何效果。

我做错了什么?

【问题讨论】:

    标签: javascript casting d3.js


    【解决方案1】:

    我想通了,显然 ids 不能以数字开头。

    【讨论】:

    • 谢天谢地有人这么说,我要花很长时间才能意识到!
    • 你为我节省了很多时间。
    猜你喜欢
    • 2015-03-20
    • 1970-01-01
    • 2015-03-24
    • 2021-09-27
    • 2021-09-07
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多