var selectedField = component.get("v.selectedField");
var resultArray = selectedField.split(',');
when I use split method display this error,who could tell me why? Error: Uncaught Action failed: [selectedField.split is not a function]
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityvar selectedField = component.get("v.selectedField");
var resultArray = selectedField.split(',');
when I use split method display this error,who could tell me why? Error: Uncaught Action failed: [selectedField.split is not a function]
Thanks your help.
Because my selectField
is used in lightning:select value="{!v.selectField}"
.
I add a toString
method convert to String
and now it works.
var resultArray = selectedField.toString().split(',');
aura:attribute
are weird wrapper objects built into Lightning instead of native JS objects. Or you might get something like an array containing one string instead of a string. So yeah you occasionally have to coerce it to the right type to manipulate it.
Oct 27, 2018 at 16:45
lightning:select
that makes sense. It's exactly as I was saying - it returns an array instead of one String, because the same component is also capable of multi-select.
Oct 27, 2018 at 16:46