检查picklist值是否包含函数中的字符串

时间:2018-03-26 16:20:49

标签: javascript arrays string sorting filter

我根据检查过滤记录列表是否fieldname值等于所选的picklistvalue。我的fieldname值可以包含更多值,例如:value1; value2; value3。我想检查picklistvalue是否为例如值2,选择记录(等于)。

例如:

 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"}]

我的过滤器如下:

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

我试过了:

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 });

1 个答案:

答案 0 :(得分:0)

我成功完成了以下工作:

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