Usually, data in is saved as an array, for example, ['value1', 'value2'], but when returns the data, it is stringified as
"['value1', 'value2']". If the data is used in components, for example, to show an intialValue, it is not seen as an array but rather as a string. Use the =$eval before the expression to return the data in an array.
Example
=$eval(@ctx.datasources.profile.food)
dropdown-dd
children:-type: component.form
instanceId: food-selection
options:children:-type: component.dropdown
instanceId: meals
options:label: meal options
data:[email protected]# use eval to return an array on food selected in the dropdown initialValue: =$eval(@ctx.datasources.food.name)
item:type: component.dropdown-item
options:title:[email protected]value:[email protected]
SQL Configuration
Data is sent as an array, for example, ['value1', 'value2'], SQL then saves the data as
VARCHAR(MAX), for example, 'value1, value2'. If the data is used in components, for example, to show an intialValue, it is not seen as an array but rather as a string. Use the =$split before the expression to return the data in an array.
There could be a scenario where there is only one string inside an array. Use the =$.count to determine if there is only one string in the array or more. If there are more than one, include $.split in the expression.
children:-type: component.form
instanceId: food-selection
options:children:-type: component.dropdown
instanceId: meals
options:label: meal options
data:[email protected]# Count to see if there is only 1 string or more initialValue: =$count($split(@ctx.datasource.profile.food, ',')) = 1 ? @ctx.datasources.profile.food:$count($split(@ctx.datasources.profile.food, ',')) >1 ? $split(@ctx.datqasources.food, ','):nullitem:type: component.dropdown-item
options:title:[email protected]value:[email protected]
Create a filtered list from an array of records
Filter an array of records to display specific data and perform expression transformations over the data.
We will display a list of people from the array of records, then filter them and display those that have entered a name. We will display their initials as a left avatar and add a label to each list item to display whether they are registered.