I have a Lightning Component that allows additional rows to be added in between existing rows. The rows are represented by a facet:
<aura:attribute name="payments" type="Aura.Component[]"/>
and the helper code that adds a row is:
var index = ...;
$A.createComponent("c:payment", {...}, function(newComponent, status, error) {
if (status === "SUCCESS") {
var rows = component.get("v.payments");
rows.splice(index, 0, newComponent);
component.set("v.payments", rows);
} else {
...
}
}
I've added JavaScript debugging output to confirm that the rows
array is being modified as I expect and debug markup to confirm the DOM order which is not consistent. The inconsistency is repeatable with the new rows appearing at about half as many rows down as I would expect from the index; I wonder if the logic that finds the DOM insertion point for the new DOM elements is getting it wrong.
What's causing this behavior? How can I fix it?
PS
In this failing case c:payment
creates a <tr>
inside a <tbody>
. I have similar code creating a <div>
inside a <div class="slds-grid">
that doesn't have this problem.
PPS
Changed to using <div>
and that didn't help.