Iterating through an array.array type in Perspective?

I have a table with a dataset that uses a named query, that I use a transform on to turn it into an array of json objects.

Here’s an example item in the dataset
image

I am trying to iterate thruogh all of the rows in a onChange property on the binding but I can’t seem to do it. All I can tell is that the type of the dataset is array.array. getRowCount and range(len(ds)) both don’t seem to work.

Anyone know how to iterate through this?

When I try this

for items in currentValue.value:
	system.perspective.print(str(items))

I get

QV[{style=QV[{backgroundColor=[#ffffff, Good, Thu Feb 06 15:06:57 EST 2020 (1581019617702)]}, Good, Thu Feb 06 15:06:57 EST 2020], value=QV[{Item=[Safety Shoes, Good, Thu Feb 06 15:06:57 EST 2020 (1581019617702)], Required=[1, Good, Thu Feb 06 15:06:57 EST 2020 (1581019617702)], Value=[433, Good, Thu Feb 06 15:06:57 EST 2020 (1581019617702)], Default=[0, Good, Thu Feb 06 15:06:57 EST 2020 (1581019617702)], Notes=[Steel toe, Good, Thu Feb 06 15:06:57 EST 2020 (1581019617702)]}, Good, Thu Feb 06 15:06:57 EST 2020]}, Good, Thu Feb 06 15:06:57 EST 2020]
data: [
    0: {
        style: {
            backgroundColor: '#ffffff'
        },
        value: {
            Item: 'Safety Shoes',
            Required: 1,
            Value: 433,
            Default: 0,
            Notes: 'Steel toe'
        }
    }
]

This might not be a complete breakdown of the first data entry, but it should be close.
What you are seeing here is your data as an array, but in simplified easy-to-read form. Behind the scenes, all of these values are Qualified Values, which means that they all have a value, a quality, and a lastChanged timestamp. On top of that, you have nested complex objects which are essentially HashMaps. Depending on what value you’re trying to actually read, you might need to do something like:

# please keep in mind that I have not run this myself and it is only an example
for row in currentValue.value:
    # to get the 'Item' attribute as a simple str value:
    my_item_value = row.value['value'].value['Item'].value

Here’s the same script with a breakdown:

for row in currentValue.value:
    # to get the 'Item' attribute as a simple str value:
    row_qv = row
    row_as_object = row_qv.value
    value_obj_as_qv = row_as_object['value']
    value_obj_as_object = value_obj_as_qv.value
    Item_as_qv = value_obj_as_object['Item']
    Item_qv_as_str = Item_as_qv.value
1 Like