D3.js: Get an array of the data attached to a selection?

后端 未结 4 500
耶瑟儿~
耶瑟儿~ 2021-02-01 17:39

I\'d like to get an array of all the data attached to a selection in D3.

I\'m working with the example from the General Update pattern, and trying this:

         


        
4条回答
  •  执念已碎
    2021-02-01 17:59

    If you want to access the entire data array from within a modification function, e.g., selection.attr, you can use the fact that the entire selection is passed to the modification function as its third argument. So you can reconstruct the data array as follows:

    mySelection.attr("stroke", (_, __, nodes) => {
      let data = d3.selectAll(nodes).data()
      // Now you can use data.
    }
    

提交回复
热议问题