Class toggle works on Array but not Data Store?

We were using an array to store some data but dropped the idea and replaced with a Data Store. There is a simple class toggle to set opacity when the images uid is found in the array. This all worked fine.

dmx-class:opacity-40="selectedmediaitemarray.items.contains(mediaLibraryItemUID)"

BUT… When we try to apply the same to the replacement Data Store the toggle does not apply?

dmx-class:opacity-40="cmpSelectedMediaItems.data[0].contains(mediaLibraryItemUID)"

Or.

dmx-class:opacity-40="cmpSelectedMediaItems.contains(mediaLibraryItemUID)"

Neither way seems to work? Am I being daft? The data store is called ‘cmpSelectedMediaItems’. Any advice on rectification would be most obliged kind people! maybe its a Friday thing…?

:smiley:

Hi Dave, which of the data store properties you want to check if it contains some value? Also what’s your data store structure?

cmpSelectedMediaItems.data[0].contains

doesn’t look like a correct expression to me.

Probably right, I hacked about trying various combinations. The value is the mediaLibraryItemUID. We know its in the store as can see it in the Application tab of Chrome. As I said probably me being a bit stupid.

2020-12-18_13-35-31

Please use:

cmpSelectedMediaItems.data.where(`mediaLibraryItemUID `, 'f09....ab', 'contains')

or if you want to check if it equals and not contains then use:

cmpSelectedMediaItems.data.where(`mediaLibraryItemUID `, 'f09....ab', '==')

Thanks @Teodor will give it a try. Any reason why its not as simple as the method used for the array? Was straight forward. Sometimes its a bit difficult keeping up.

:slight_smile:

Because the structure the data store uses is different than the flat structure the array component uses :slight_smile:

1 Like