json - Get an array of distinct values for a column from dojo/store -
my scenario:
this test data in json array format:
var testdataobj = [   { col1: 'p0',   col2: 1, tbl: 'p',   col3: '14/01/2013', col4:'bob'},   { col1: 'p1',   col2: 2, tbl: 'p',   col3: '14/01/2013', col4:'sandy'},   { col1: 'p2',   col2: 3, tbl: 'p',   col3: '14/01/2013', col4:'jason'},   { col1: 'p3',   col2: 4, tbl: 'p',   col3: '14/01/2013', col4:'jason'},   { col1: 'p4',   col2: 5, tbl: 'p',   col3: '14/01/2013', col4:'sandy'}, ]; i created object of dojo/store/memory following:
require(["dojo/store/memory"], function(memory){   var gctsteststore = new memory({data: testdataobj}); }); what want achieve:
i want array of distinct values of column col4:
var distinctcolumnvalues=gctsteststore.getdistinctvaluesfromcolumnname('col4'); //distinctcolumnvalues= ['bob','sandy','jason'] my request:
currently, looping through json array testdataobj achieve result, exploring more elegant solution using dojo/store's api.
i using dojo/store/memory here can accept solution other type of dojo/store.
thanks.
there no built in apis getting distinct values memory store. need write own method in javascript getting distinct. below 1 way of writing it.
var unique = {}; var distinct = []; for( var in array ){  if( typeof(unique[array[i].col4]) == "undefined"){   distinct.push(array[i].col4);  }  unique[array[i].col4] = 0; } 
Comments
Post a Comment