【问题标题】:d3 localStorage.getItem() compare arrays .filter()d3 localStorage.getItem() 比较数组 .filter()
【发布时间】:2015-07-05 16:42:21
【问题描述】:

我正在尝试从 localStorage 取回值; div 元素中的多个点击计数器。 它们存储在 localStorage 中的 key = this.id 下单击;这些值是 div 的 innerText。

现在:1. 我过滤选择以查找 arraylocal 中元素 ID 的匹配项 2.如果匹配,设置html。

   d3.selectAll(".numberCircle").filter((d) -> this.id in arraylocal).html(localStorage.getItem(((d) -> this.id))
  1. 我想使用“this.id”从 localStorage 中取回值(来自元素的 innerText)。

  2. 如何设置 localStorage.getItem(x????x) 以读取正确的键/值对(其中 key = this.id)?

因此:对于每个数组过滤器匹配,我还需要与该匹配相关的 localStorage

【问题讨论】:

    标签: javascript html d3.js local-storage


    【解决方案1】:

    解决方案:

    updateLabels = function() {
    
    var arraylocal, key;
    

    localStorage 中的键反映了此解决方案中的字符串,因为我为 setItem 设置了字符串值,例如:setItem(string,string)

    arraylocal 是一个包含这些字符串的数组

    arraylocal = [];
    for (key in localStorage) {
      arraylocal.push(key);
      console.log(arraylocal);
    }
    

    每个气泡标签名称都有一个字符串值 textValue(d)。

    当字符串值 textValue(d) 匹配数组中的字符串 'key' 时,过滤器会改变节点的样式

    d3.selectAll(".bubble-label-name").filter(function(d) {
      var ref;
      return ref = textValue(d), indexOf.call(arraylocal, ref) >= 0;
    }).style("border", "2px solid red");
    
    };
    

    【讨论】:

      猜你喜欢
      • 2015-03-02
      • 2020-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      • 2018-09-18
      • 2016-01-24
      相关资源
      最近更新 更多