I have a lightning component that is pulling data from Products (product2) and it has a custom field (Benefits__c) that is multi-select picklist. I need to display those multiselect values in component separately. Right now they are appear with ;
(semicolon) between each value.
I have read How to use Split() function inside an Expression in lightning component but I could not follow it completely.
Component
@AuraEnabled
public static List<Product2> returnProducts(string stateCode) {
return [SELECT Id, Name, Plans_by_State_Description__c, Grid_Sequence__c, Plans_by_State_Benefits__c
FROM Product2
WHERE State__c =: stateCode];
}
Below is my JS-Controller (I have tried some things but to no avail)
var action = cmp.get("c.returnProducts");
action.setParams({ stateCode : "WI" });
action.setCallback(this, $A.getCallback(function (response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
//console.log(JSON.stringify(result) );
var someMap = {};
if(result){
for( var key in result ){
JSON.stringify(key + '>' + value);
if (key=="Benefits__c"){
someMap['Benefits1'] = value.split(';')[0];
someMap['Benefits2'] = value.split(';')[1];
someMap.push({key:key, key0: value.split(';')[0], key1:value.split(';')[1], value:output[key]});
}
}
//console.log(JSON.stringify(someMap) );
cmp.set("v.products", someMap);
}
} else if (state === "ERROR") {
var errors = response.getError();
console.error(errors);
}
}));
$A.enqueueAction(action);
}
I want to split the values of the multi-select and then map them in the markup. Not sure where to go from here now.