You have two options for saving old data attached to an element to identify changes after a new data connection.
The first option, as you suggested, is to use data attributes. This SO Q & A describes this approach . What to consider:
- all your data values ββwill be forcibly bound to strings.
- you will need a separate method / method attribute for each aspect of the data.
- you manipulate the DOM so that it can slow down if you have a lot of elements or a lot of data for each
- data is now part of the DOM, so you can save it with an image or access other scripts
The second option is to store the data as the Javascript property of the DOM object for the element, just as d3 stores the active data as the __data__ property . I discussed this method in this forum post .
General approach:
selection = selection.property(" __oldData__", function(d){ return d; } );
Of course, you can use any name for the old data property, it just means that a lot of "_" characters will be added around it to avoid spoiling any of the browser-based DOM properties.
Ameliabr
source share