Dict databinding in repeating panel

I’m building a program to check our stock on differences. I have two dict lists that I first merge from a SimpleObject column into 1 large dict with the example output:


{'100032': {'STOCK_ID': 100032, 'STOCK_AANTAL': 1}, '100033': {'STOCK_ID': 100033, 'STOCK_AANTAL': 1}, '100039': {'STOCK_ID': 100039, 'STOCK_AANTAL': 2}, '100040': {'STOCK_ID': 100040, 'STOCK_AANTAL': 1}, '1000623': {'STOCK_ID': 1000623, 'STOCK_AANTAL': 4}, '1000663': {'STOCK_ID': 1000663, 'STOCK_AANTAL': 1}}

I now want to display this dict in a datagrid repeating panel, to find stock differences. I have a problem with the data binding.

Self.item[‘STOCK_ID’] or ['STOCK_AANTAL’] on databinding gives the error:


TypeError: string indices must be integers, not str. Did you initialise all data binding sources before initialising this component?

When using self.item[0] I only get 1 or 0. When i just use self.item i get the key value in the grid, but i don’t manage to acces the values in the dict.

What am I missing here? Thanks in advance!

Ok found finaly the issue. You need to convert a nested dict first to a list.

  scan_lijst_opti = []
  
  for key, value in lijst.items():
    dict_item = {}
    dict_item['STOCK_ID'] = key
    dict_item['STOCK_AANTAL'] = value['STOCK_AANTAL']
    scan_lijst_opti.append(dict_item)
3 Likes