【问题标题】:Is modifying data already inserted to crossfilter possible?是否可以修改已插入交叉过滤的数据?
【发布时间】:2014-02-28 19:26:33
【问题描述】:

查看Crossfilter API,我没有看到任何关于如何修改已添加到 Crossfilter 的行的信息。

是否绝对禁止/不可能修改现有行?比如说,通过添加更多字段或修改一行的字段值?似乎删除所有数据并将其读取到交叉过滤器是唯一的方法,但这意味着丢失所有当前的过滤器、尺寸等。

【问题讨论】:

  • 没错,您需要删除并重新添加它们才能在索引中更新它们。否则会不一致。
  • @Gordon。是的,我害怕那个。换句话说,我需要先做 crossfilterInstance.remove(),然后再做 crossfilterInstance.add(newRecordsWithMoreFields)。我愿意在这里接受这个答案。

标签: javascript crossfilter dc.js


【解决方案1】:

如果您创建一个“唯一维度”,它为数据集中的每个条目(如 ID 列)返回一个唯一值,您可以使用这样的函数来更改单个条目而不会丢弃所有内容:

function editEntry(id, changes) {
    uniqueDimension.filter(id); // filter to the item you want to change
    var selectedEntry = uniqueDimension.top(1)[0]; // get the item
    _.extend(selectedEntry, changes); // apply changes to it
    ndx.remove(); // remove all items that pass the current filter (which will just be the item we are changing
    ndx.add([selectedEntry]); // re-add the item
    uniqueDimension.filter(null); // clear the filter
    dc.redrawAll(); // redraw the UI
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多