【发布时间】:2015-03-02 01:54:12
【问题描述】:
我正在有条件地设置 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"))
为什么使用硬编码的数组内容有效,但是当我使用数组变量时却不行?
【问题讨论】:
标签: javascript arrays d3.js coffeescript global-variables