Hi @forza,
In my case, I was interested in the YT tutorials to learn ES6 for Fuse so that I could avoid using Observables. So I don’t use them, but I will try and help you.
First off, you have a typo in your clicked
function - instead of value
you have valeu
. It should read:
isOpen.value = false;
You are also missing a semi-colon in your toggleOpen()
function. It should read:
isOpen.value = !isOpen.value;
Currently, your code exports options
“as-is”, which is an array of strings. This means that your UX markup will only have access to an array of strings - not very useful.
The tutorial exports options
in a way that maps a function to the options
array and iterates over each item. It returns more than just the array, making it way more useful.
options: options.map(function(option){ //map to options array and refer to each item (i.e. the currentValue) as option
return{
title: option, // each title will return each option, which you can use to label your buttons, populate droplist, etc.
isSelected: Observable(function(){
return selected.value === option; // set the value of `selected` to whichever value `isSelected` is `true`
}),
By creating separate “handles” from the options array, you can treat them separately in your UX markup. Title
can be used to populate the value for each Panel
in the Each.Items
collection.
Conversely, when IsSelected
becomes true for a Panel
item, the value of selected
(which is an Observable
) will be updated to that panel’s value. Since the Panel
items were populated with the title
value, selected
will be set to the respective title
value.
Setting the value in this way allows UI changes like user selection to communicate to the business logic of your application. Now if you wanted to, you could do something with the selected
value, such as run a query, generate a greeting, etc.
To learn more about IsSelected
, see IsSelectedFunction Class in the documentation.
(BTW, IsSelected
is Pascal Case in the docs but Camel Case in the example. It seems to work either way…)
Click here to watch Anders explain his export scripting in the YouTube tutorial.
Read more about Array.prototype.map()
in the official Mozilla JavaScript documentation here.
Map
is nice because it’s an immutable way to run a function on a value or an array of values.
Hope this helps!
PS - “Ananas” in English is “Pineapple”