Variable from Multiselect in Collection

Hi,

I have a page of results which is filtered by a sidebar filter. Because I’m working with an external API pulled into Xano, each user will use tag filters, but they are displayed in different groups. The groups are collections.

In the screenshot above, Style, Frequency, and Type are each items in a collection. In each item, there is a multiselect in which they can choose filters. Each selection in the multiselect corresponds to an integer.

I am passing the results of these filters into a variable, using this method.

The result is this:

{
“2”: {
“domEvent”: {},
“value”: [
2,
5
]
},
“3”: {
“domEvent”: {},
“value”: [
13,
8
]
},
“4”: {
“domEvent”: {},
“value”:
}
}

My goal is to get a list of the values combined: [2, 5, 13, 8]. I can do parsing in Xano, but is there any way to get closer to my goal in WeWeb before doing that Xano parsing? The number of objects will vary by user.

What I would do, is rather save the items from each select in an array, you can do this with Change Variable ValueInsert at an index and use your item.context.index

then it’s as simple, as doing a rollup nocode formula

I mean, you’re storing the items as “numbered” object’s properties (which are objects), so you might as well use an array, which basically is the same thing, but with some perks, like rollup formula.

Thank you, @Broberto. This is still a few steps beyond my knowledge at this point.

I can get at context.item.index. I see the “Insert at an Index” when I am using a an “array” variable. But I think I’m missing some granular steps here. Where are the values being collected before being rolled up?

I tried just adding all selected items to the end of an array, but then the deselect in the multiselect doesn’t work.

This is my setup

I bind an array so I can have a bound “collection” of multiselects

I set an action to update One item ad index that is item.index (the outermost)


Then I set the value to the event value array

Finally, I use a function to join these arrays,

The function is the following

let newArr = []

// replace variables[...] with your array variable where you store the items from selects
variables[/* arr */'155b806a-1da6-40ab-bf17-23050456fafc'].map((item)=> {newArr=[...newArr, ...item]})

return newArr

With update one item, you also get to edit em, not just add them.

1 Like

Thank you!

No worries. Let me know if it helps! :slight_smile:

1 Like

Yes, it worked perfectly. Thanks!

1 Like