I’ve got a bunch of Raphael element objects on a canvas and have associated data with each, like so:
element.data('dataVal',x);
In the above example, I’d like to know where x is stored. I’ve been looking through the source for Raphael.js and have zeroed in on this section:
elproto.data = function (key, value) {
var data = eldata[this.id] = eldata[this.id] || {};
if (arguments.length == 1) {
if (R.is(key, "object")) {
for (var i in key) if (key[has](i)) {
this.data(i, key[i]);
}
return this;
}
eve("raphael.data.get." + this.id, this, data[key], key);
return data[key];
}
data[key] = value;
eve("raphael.data.set." + this.id, this, value, key);
return this;
};
So, my hunch is that ‘eldata’ is a property of a Raphael paper object and that ‘eldata’ contains objects for each Raphael element, and it is in these objects that the data are stored.
In essence, my question is: Once I’ve created a Raphael canvas, added elements, and added data to those elements, how would I access the data (without using a Raphael function)? I’ve tried simple stuff like looking for R.eldata (where R is a Raphael canvas), but that wasn’t fruitful.
Your help is appreciated!
eldatais a local variable defined within a closure (line numbers on the left from v2.1.0):Because it’s enclosed, it can only be accessed by a function defined within that same closure. So, you will have to use Raphael’s
dataandremoveDatamethods to access it.