插入后修改交叉过滤器中的字段值

时间:2014-03-18 09:08:36

标签: crossfilter

我需要在插入新记录之前修改crossfilter中所有记录的字段值。 API没有说出任何相关信息。有没有办法做到这一点 ? 即使它对我来说真的很有用。

3 个答案:

答案 0 :(得分:0)

查看代码,数据数组在crossfilter函数中保存为私有局部变量,因此无法直接获取它。

话虽如此,看起来Crossfilter确实试图最小化它所做数据的副本数量。因此,传递给crossfilter.dimensiondimension.filter的回调函数将从数据数组中传递实际记录(使用本机Array.map),因此对记录所做的任何更改都将对主要记录。

话虽如此,您显然需要非常小心,不要更改现有维度,过滤器或组所依赖的任何内容。否则,您最终会得到与内部Crossfilter结构不一致的数据,随之而来的是混乱。

答案 1 :(得分:0)

关于.remove很酷的事情是它只删除与当前应用的过滤器匹配的条目。因此,如果您创建了一个独特的维度'为数据集中的每个条目(如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
}

答案 2 :(得分:0)

至少你可以做cf.remove()然后用cf.add()读取调整后的数据。