Json Array and OH-Repeater

I am trying to cycle through a json array with oh-repeater and need a bit of help, probably on the syntax.

json string is stored in an item and looks like this:

[{"sName":"TestItem","sAlarm":"FIRE","sTime":"12.08. 16:45","isCritical":true},
{"sName":"TestItem","sAlarm":"OVERTEMP","sTime":"12.08. 16:46","isCritical":false}]

Widget code:

- component: f7-list
    inset: true
    mediaList: true
      - component: oh-repeater
          for: rItem
          fragment: true
          sourceType: array
          in: =JSON.parse(@@vAlarme)
            - component: f7-list-item
                badge: =loop.rItem.sAlarm
                badgeColor: red
                subtitle: =loop.rItem.sTime
                swipeout: true
                title: =loop.rItem.sName

The resulting list is empty. Browser inspect:


(No matching selector or style)

That should work.

The only real issue I can see is with @@vAlarme. If vAlarme is the actual name of the item then that needs to be in quotes @@'vAlarme' otherwise the expression treats it as a variable that holds a string value representing some arbitrary item’s name.

1 Like

Thanks Justin!

1 Like

We’ve all been there :wink: .

1 Like

I should have known it…

One follow up question please:
Within the widget I pass over a selected object (loop.rItem which contains {“sName”:“TestItem”,“sAlarm”:“FIRE”,“sTime”:“12.08. 16:45”,“isCritical”:true}) to a rule

action: rule
actionRule: AlarmDelete
  deleteObject: =loop.rItem

which works fine.
Within this rule I try to find jsonArray’s index for the selected object, so that I can delete it from jsonArray.

var i = jsonArray.indexOf(deleteObject);
delete jsonArray[i];

However, i = -1 (not found) whatever other variations I have tried (for more than 2 hours).
Could you point me to the right direction?

I believe that object equivalence there is handled by reference, so the objects are not equal even though they have the same properties.

You can create you own function for object comparison and pass that to the findIndex() method of the array, but honestly, that’s a lot of work when your widget loop already knows the index of the object. Just pass a second variable to the rule:

action: rule
actionRule: AlarmDelete
  deleteObject: =loop.rItem
  indexObject: =loop.rItem_idx