Perspective instances (flexrepeater) help

I have a Dataset that I query into the instances binding. I loop through the data and make some adjustments in my new dataset. a single column data set errors out. a list errors out the only format that works is json. I can RETURN a json but when I adjust it in the binding then the object that I start with is no longer a dataset. Is there a quick way to change this?

Add a custom property to the repeater. Move the original dataset binding there (and make it private, as you won't need it transmitted to the browser). Bind the original instances property to this custom property, and add a transform to yield the desired json. Perform the adjustments in the same loop. Your instances will get the adjustments, and both dataset and adjusted json will be available to other event scripts.

1 Like

This leaves me in the same position. My source query can be "returned" as a dataset or JSON. This does not just alter the return but the structure of the provided data before the transform.

If I use expression or prop binding on on my custom dataset I need to parse through it manually again and convert it to a json object?

Yes, you will need to convert to a list of dictionaries to mimic the JSON return format. The transform would look something like this:

def transform(self, value, quality, timestamp):
	cNames = list(value.columnNames)
	output = []
	for r in range(value.rowCount):
		newRow = dict([(c, value.getValueAt(r, c)) for c in cNames])
	return output

That is essentially what JSON format does under the hood. You can insert your code to make adjustments between creating newRow and appending it to output.

This solution does work however I am stumbling with the dictionary format but the single line is confusing me. Can I create multiple dictionary entries or does the list limit how many "rows" each dictionary can have?
Additionally, I am doing a tag read in the for loop and trying to use output.insert(index, newRow) to place my instances in a certain order dynamically. While my code seems to be working the list order itself does not change. Am I missing something in how this object is working?

Show your current code, a sample of your data, and show how you want it to come out. Then we can make concrete suggestions.

(Don't show screenshots of code. Paste code, select what you paste, then click the "Preformatted Text" button to make a code block.)

Python's dictionary constructor (the dict() function) accepts an initializer in the form of nested iterables, where the inner iterables (I used tuples) are length two: a key and a value. So the line beginning with newRow = is constructing a dictionary and initializing it with a list of tuples: column name and value for that row & column. You might want to look up "list comprehensions" in the python docs.

Between that row and the .append() operation, you can make more assignments to the dictionary to make arbitrary computed columns, of the form:

    newRow['someColumnName'] = someExpression

You can also re-assign over the original values if needed. Or use python's del statement to discard information.