问题
I am trying to get values back from localStorage; multiple click counters in div elements. They were stored on click under key = this.id in localStorage; the values are the innerText of the divs.
Now: 1. I filter the selection looking for a match for element-ids in arraylocal 2. if match, set the html.
d3.selectAll(".numberCircle").filter((d) -> this.id in arraylocal).html(localStorage.getItem(((d) -> this.id))
I would like to get values ( innerText from elements ) back out of localStorage using 'this.id'.
How can I set localStorage.getItem(x????x) to read the proper key/value pair ( where key = this.id ) ?
Thus: for each array filter match, I also need the localStorage value that is related to that match.
回答1:
Solution:
updateLabels = function() {
var arraylocal, key;
key in localStorage reflects a string in this solution, as I set a string value for setItem, e.g.: setItem(string,string)
arraylocal is an array containing these strings
arraylocal = [];
for (key in localStorage) {
arraylocal.push(key);
console.log(arraylocal);
}
each bubble-label-name has a string value textValue(d).
The filter changes the style of the nodes when the string value textValue(d) matches a string 'key' in the array
d3.selectAll(".bubble-label-name").filter(function(d) {
var ref;
return ref = textValue(d), indexOf.call(arraylocal, ref) >= 0;
}).style("border", "2px solid red");
};
来源:https://stackoverflow.com/questions/28183376/d3-localstorage-getitem-compare-arrays-filter