我有这个cf:
const paymentsCf = crossfilter([
{id: 1, quantity: 2, total: 190, tip: 100, type: "tab"},
{id: 2, quantity: 2, total: 190, tip: 100, type: "tab"},
{id: 3, quantity: 1, total: 300, tip: 200, type: "visa"}
]);
我正在通过ID创建维度,并按以下方式对其进行过滤:
const dimension = paymentsCf.dimension(({ id }) => id);
dimension.filter(2);
如果我做得console.log(paymentsCf.groupAll().value())
公平,我就会明白1
。
但是,如何访问整个过滤对象以获取数量,总数,小费和类型?
我知道我可以做,feedbackCf.all()
但这可以显示所有三个对象。不仅过滤了。
谢谢!
您只需要添加top()
方法即可公开结果:
const dimension = paymentsCf.dimension(({ id }) => id);
const res = dimension.filter(2);
res.top(1);
输出:
[ { id: 2, quantity: 2, total: 190, tip: 100, type: 'tab' } ]
从1.4版本开始,还有crossfilter.allFiltered()。效果相同但未排序,您无需指定所需的结果数。