javascript - d3 localStorage 比较数组.filter CoffeeScript ;数组变量不起作用

标签 javascript arrays d3.js coffeescript global-variables

我正在有条件地设置 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/

相关文章:

javascript - 在响应式设计中按比例裁剪图像?

java - java中比较两个数组列表

javascript - 在上下文中使用 with 语句是个好主意吗?

javascript - 需要通过坐标识别Img标签

c++ - 将结构数组传递给函数C++

javascript - 无法隐藏标签 'behind' 旋转的 D3 Globe

javascript - 使用 d3.js 和 Three.js 绘制轮廓图

javascript - d3 找不到线性属性/方法?

javascript - Google Apps脚本-如何登录和获取数据?

javascript - Firebase 值已正确提取但无法访问?