如何只获取那些在 crossfilter 中具有特定代码的数据

How to get only those data which have particular code in crossfilter

我有以下数据集

var data=
[
{code:501, value:25},
{code:501, value:30},
{code:501, value:30},
{code:501, value:35},
{code:501, value:60},
{code:502, value:25},
{code:502, value:25}
]

我只想取回仅包含代码为 501 的数据的数据集。 我尝试了以下代码

var ndx=crossfilter(data);
var dim1=ndx.dimension(function(d){return d.code});
var filtereddata=dim1.filter(501);

但是它不起作用。它没有返回我想要的数据。我尝试使用控制台打印返回的数据,但它打印了一些模糊的东西。

function getData(){
  var range = $("#range").val()*1;
  if(isNaN(range)){
    alert("Kindly Enter Valid Number");
  }else{
    var data=
[
{code:501, value:25},
{code:501, value:30},
{code:501, value:30},
{code:501, value:35},
{code:501, value:60},
{code:502, value:25},
{code:502, value:25}
];

var ndx=crossfilter(data);
var dim1=ndx.dimension(function(d){return d.code});
var filtereddata=dim1.filter(range);
    alert("Requested Data is\n"+(JSON.stringify(dim1.top(Infinity))));
}
  
}  
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.11/crossfilter.js"></script>
<input type='text' id='range'>
<input type='button' value='getData' onclick='getData()'>

我想你正在找这个.... :D