d3 adding data attribute conditionally

后端 未结 5 1471
悲&欢浪女
悲&欢浪女 2021-02-01 14:01

I\'m creating a table with d3 to be used by the FooTable jquery plugin and this requires having some data- attributes in the header row. But not all columns have all the data a

5条回答
  •  情书的邮戳
    2021-02-01 14:51

    A cleaner is to use filter

    .filter(d => !!d["data-class"]) // filter only data with the "data-class" property
    .attr("data-class", d => d["data-class"])
    

提交回复
热议问题