0

I filter a list of records based on a check if fieldname value equals selected picklistvalue. My fieldname value can contain more values for example: value1;value2;value3. I want to check if picklistvalue is for example value2 that the record is selected(equal).

So for example:

 i=1;

checkCheckboxOnOff =[{"fieldName":"Categorie__c","picklistValue":"value2"}]

fieldName= value1;value2;value3

picklistvalue=value2



 serverlist= [ {"Id":"123",Categorie__c":"value1,value2,value3"},  {"Id":"124",Categorie__c":"value1"},  {"Id":"125",Categorie__c":"value3"}]

My filter is as follows:

var opleidingfilter = serverList.filter(function(item) { return item[checkCheckboxOnOff[i].fieldName] == checkCheckboxOnOff[i].picklistValue});

I tried:

var opleidingfilter = serverList.filter(function(item) { return str.includes(item[checkCheckboxOnOff[i].fieldName]) == checkCheckboxOnOff[i].picklistValue});



var opleidingfilter = serverList.filter(function(item) { return item[checkCheckboxOnOff[i].fieldName].indexOf(checkCheckboxOnOff[i].picklistValue) == -1 });
Thomas
  • 181
  • 1
  • 9

1 Answers1

0

I managed to get the following working:

var opleidingfilter = serverList.filter(function(item) { return (item[checkCheckboxOnOff[i].fieldName]).includes(checkCheckboxOnOff[i].picklistValue)});

Thomas
  • 181
  • 1
  • 9