d3 localStorage.getItem()比较数组.filter() [英] d3 localStorage.getItem() compare arrays .filter()
问题描述
我试图从localStorage获取值; div元素中的多个点击计数器。
他们存储在点击下key = this.id在localStorage;这些值是div的innerText。
现在:1.我过滤了选择,寻找一个匹配的元素id在arraylocal
2.如果匹配,设置html。
d3.selectAll(。numberCircle)。filter((d) - > this.id in arraylocal).html(localStorage.getItem((d) - > this.id))
-
我想使用'this.id'从localStorage获取值(innerText从元素)。
-
如何设置localStorage.getItem(x ???? x)来读取正确的键/值对(其中key = this.id)?
因此:对于每个数组过滤器匹配,我还需要与该匹配相关的localStorage value 。
解决方案:
updateLabels = function
var arraylocal,key;
解决方案,因为我为setItem设置了一个字符串值,例如:setItem(string,string)
arraylocal是一个包含这些字符串的数组
arraylocal = [];
for(key in localStorage){
arraylocal.push(key);
console.log(arraylocal);
}
每个bubble-label-name都有一个字符串值textValue(d) / p>
当字符串值textValue(d)匹配数组中的字符串'key'时,过滤器更改节点的样式
d3.selectAll(。bubble-label-name)filter(function(d){
var ref;
return ref = textValue style(border,2px solid red); d)
};
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.
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");
};
这篇关于d3 localStorage.getItem()比较数组.filter()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!