查看 Crossfilter API ,我没有看到任何关于如何修改已添加到 Crossfilter 的行的提及。
是否绝对禁止/不可能修改现有行?比如说,通过添加更多字段或修改一行的字段值?似乎删除所有数据并将其读取到交叉过滤器是唯一的方法,但这将意味着丢失所有当前过滤器、维度等。
最佳答案
如果您创建一个“唯一维度”,它为数据集中的每个条目(如 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
}
关于javascript - 是否可以修改已插入交叉过滤器的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21559056/