我正在有条件地设置 div 的 CSS。为此,我使用 .filter。过滤器比较 2 个数组。 当我运行下面的代码时,它不起作用。当我对 array_1 内容进行硬编码(从控制台获取;取消所示代码中的注释)时,它确实可以工作。
我假设循环产生的数组没有及时为过滤函数做好准备?
labelEnter.append("div")
.attr("class", "bubble-label-name")
.text((d) -> textValue(d))
arraylocal = []
typeofKey = null
for key of localStorage
typeofKey = (typeof localStorage[key])
array = arraylocal.push key
break
console.log(array)
# array = ["show", "cum", "nec", "show"]
console.log(d3.selectAll(".bubble-label-name").filter((d) -> textValue(d) in array).style("border", "1px solid red"))
为什么使用硬编码数组内容可以工作,但当我使用数组变量时却不行?
最佳答案
您似乎期望 arrayLocal.push(key)
返回数组的副本。然而,push()
method returns a the new length of the array ,这就是将存储在您的 array
变量中的所有内容。
关于javascript - d3 localStorage 比较数组.filter CoffeeScript ;数组变量不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27764087/