I am working on a set of Lightning Components - all in the same namespace - that allow rows to be interactively added to a page and cells within the rows to be selected from database values and that works fine. When all the work is done, logic in the root table component can walk down through all the rows and cells and save the result to the database.
But I now have a case where one of my components within a row needs to find out about the content from other rows. So, using HTML terminology, a td
component needs to grab information from multiple other td
components located in many tr
components in the overall table
component.
There is this post How to get parent lightning component's attribute in child component?. It says that getting hold of your parent component breaks encapsulation but suggests a work around of passing references to the parent component data to the child component - not sure why the "breaks encapsulation" argument doesn't apply for that case. Or it suggests using events to communicate.
Are there any alternatives that make sharing model data between a set of co-operating (not stand-alone) components convenient?
PS
It occurs to me that having a JavaScript model tree that parallels the structure with the appropriate part used as the aura:attribute
on each child component is one way to go. If that model had parent references as well as child collections I don't think it would be serializable from/to the server (as there would be circular references), so those parent references will have to be added/removed in JavaScript. Then my td
component can walk up and down the tree as it needs. Anyone used this approach?
PPS
I've just placed an order for Force.com Enterprise Architecture Second Edition that has a section "Lightning Architecture and Components" that may help.
<c:tableRow/>
and handle it in the Parent<c:table>
, which inturns tries to access the all<c:tableRow />
components. Once you get hold of the each row component, you can access td's value (specific td value based on the field or all fields values) usingtrInstance.find('row').get('v.myProp')
. Will this approach work for you?td
cells.