d3 localStorage.getItem() compare arrays .filter()

烈酒焚心 提交于 2019-12-25 04:07:57

问题


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))
  1. I would like to get values ( innerText from elements ) back out of localStorage using 'this.id'.

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!