Repeater list card on item array

Hello,

I try to display a list of user with a widget in OH3 (3.1.1) .
For that I’m using:

  • an item where I’ve an list of user define as JSON doc
[
{"acctype": "1", "uid": "1", "time": 1639435466, "validuntil": "2145916800", "username": "a"},
{"acctype": "0", "uid": "2", "time": 1639435466, "validuntil": "2145916800", "username": "b"}
]
  • a list card where I try to use the oh-repeater + oh-label-card
component: oh-list-card
config:
  title: User list
  simpleList: true
slots:
  default:
    - component: oh-repeater
      config:
        fragement: false
        for: item
        sourceType: array
        in: items[14_Entry_Users]
        listContainer: false
      slots:
        default:
          - component: oh-label-card
            config:
              icon: oh:man_1
              title: Username
              item: =loop.item.username
          - component: oh-label-card
            config:
              icon: oh:settings
              title: UID
              item: =loop.item.uid

But event if I try many thing, nothing happen, any idea?

Thanks in advance and take care :wink:
Guillain

The first issue is the choice of base component type here. An oh-list-card is expecting specific items as it’s children: list items. So while you can render other thing such as the oh-label-card within the list, the results are not necessarily going to be what you expect. In this case, you probably just want a more basic starting component such as an f7-card or f7-block.

Most of the other issues are with this line here:

  1. The yaml definitions interpret all inputs as strings unless you explicitly define them as expressions using the = at the front. So, in this case you are not setting the input array to your JSON text you are setting it to the literal string "items[14_Entry_Users]".
  2. To access the keys in the items object using the bracket notation, your item name must be a string. It can either be a variable that holds a string value or if its a literal string then it needs " around it.
  3. Here in the widgets, the items object has both .state. and .displayState properties, so you have to specify which you want at all times. In this case I assume you want the raw .state.
  4. Whenever you retrieve an item state in the widget yaml it is simply a string (that’s how it gets delivered by the API). So this won’t be an actual array of JSON objects until you parse that state string. The widgets can use the parse method of the javascript JSON object.

Taken together then, this line should probably be:

in: =JSON.parse(items["14_Entry_Users"].state)
1 Like

Thanks a lot for your clear and complet reply!
I put the final code (just in case if someonelse need it ^^)

uid: widget_UserList
tags:
  - user
  - list
props:
  parameters:
    - description: A text prop
      label: Prop 1
      name: prop1
      required: false
      type: TEXT
    - context: item
      description: An item to control
      label: Item
      name: item
      required: false
      type: TEXT
  parameterGroups: []
timestamp: Dec 14, 2021, 7:18:03 PM
component: f7-list
config:
  title: User list
slots:
  default:
    - component: oh-repeater
      config:
        fragement: false
        for: item
        sourceType: array
        in: =JSON.parse(items["14_Entry_Users"].state)
        listContainer: false
      slots:
        default:
          - component: oh-label-card
            config:
              icon: '=(loop.item.acctype == "1") ? "oh:man_1" : "oh:boy_1"'
              title: =loop.item.username
              label: =loop.item.uid
    - component: oh-list-item
      config:
        listButton: true
        title: Update
        action: command
        actionItem: 14_Entry_Users
        actionCommand: '{"doorip":"10.1.1.xx","cmd":"listusr"}'

firefox_2021-12-14_19-21-13

Thanks again and take care :stuck_out_tongue:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.