I’m trying to use oh:repeater dynamic to display only certain items. This basically works. But when the state changes, the items aren’t hidden or shown accordingly.
I’ve tried this both using the filter in oh:repeater and using visible on the item. Neither works.
When I toggle on “Tis the Season” all the Christmas Items immediately appear. When I toggle it off the Christmas Items disappear.
The only thing I can think of which might cause problems if you toggled the Item OFF and expected it to disappear. I can see that if you interact with an Item that Item won’t disappear even if it no longer meets the filter criteria. In my widgets above, all the Items that appear or disappear change state outside of the widget.
Note, I have no memory as to why I use oh-list-card as the top component for one, and f7-card for the others.
Your problem is the visible line. In the other expressions, you’ve used items[ITEM_NAME].state, but in this one you’ve used loop.item.state.
There is an important difference between these two. When the repeater gets the information about an item, that includes the state of the item at that moment, but the repeater stores that information in a static object. If the state of the item changes, the repeater’s loop variable DOES NOT change. This is one reason the items object exists. This is a special object that tracks the specifically needed items for the widget and DOES reflect all changes to those item states in real time. So whenever you need an expression that changes with an item state, even inside a repeater, you have to use the items object.
To get the name of the item to use with the items object inside a repeater, you do need to rely on the loop variable, so the final expression looks like this: