I might have maneuvered myself in kind of a weird spot: I created a reusable component which I placed in a repeating panel. I bound the repeating panel’s self.items to a database request and within the repeating panel’s template, I bound its self.item to the component’s self.item.
All this seems to work fairly well as I can use the Data Binding option within the component to bind self.item['something'] to some text field in the component. But something is a list and I would like to manually transform the list into a string.
I understood that the constructor is not the right place to bind the data, but form_refreshing_data_bindings. Interestingly, if I use this for
self.theTextfield.text = self.item['something']
it returns a Key Error, indicating that something is not available. If I replace this with print(self.item) I see two entries when the component is initially mounted, the first of which being empty.
something is a list and I would like to manually transform the list into a string.
Data Bindings can be arbitrary Python expressions, so you can do things like
" ".join(self.item['something'])
I’m surprised to hear that you’re not seeing self.item available in the __init__ of the ItemTemplate.
self.init_components(self, **properties) refreshes the Data Bindings, so you should see that self.item is available. Here’s an app that runs print(self.item) in the __init__ of an ItemTemplate and the correct result is printed:
(That app also shows an example of doing " ".join(self.item['something') in a Data Binding.)
Perhaps you are accessing self.item before self.init_components is called? Or perhaps there’s something odd going on with the Data Tables access. If you care to share a clone link I can take a look (you can Direct Message me if you don’t want to share it publicly).
I followed your advise and investigated why self.item was not available in __init__. I added a print statement in every constructor and found out that the forms/components/templates are executed in the order (1) DocumentEditor, (2) ParagraphBlock, (3) ParagraphList and not as I would have expected as (1) DocumentEditor, the editor which holds all paragraphs, (2) ParagraphList, the repeating panel that is filled with the (3) ParagraphBlock.
Could this be the root cause as the data flow could be interrupted?