
Loading…
nested dom-repeat with sort attribute shows duplicate entries when adding new items. #1744
I fixed this in your last jsBin also:
Original:
go: function () {
for (var i=0; i<DATA.length; i++) {
var items = [];
var cat = {'num': DATA[i].num, items: items};
this.push('categories', cat);
for (var j=0; j<DATA[i].items.length; j++) {
// `i` here is only ever 0 or 1, so you're always pushing new items
// into categories[0].items or categories[1].items
this.push('categories.' + i + '.items', DATA[i].items[j]);
}
}
}In the inner loop, i is only ever 0 or 1, so you're always pushing into the this.categories[0].items or this.categories[1].items. On the second run, you push 2 more categories, so for those you want to be pushing into this.categories[2].items and this.categories[3].items:
Fixed:
go: function () {
for (var i=0; i<DATA.length; i++) {
var items = [];
var cat = {'num': DATA[i].num, items: items};
this.push('categories', cat);
for (var j=0; j<DATA[i].items.length; j++) {
// push onto the MOST RECENTLY ADDED category's items
this.push('categories.' + (this.categories.length-1) + '.items', DATA[i].items[j]);
}
}
}This works as expected:
@kevinpschaaf this does NOT resolve the issue. if you look at your 'working as expected' version, you'll still see a duplicate entry at the end of each category. THAT is the issue I'm reporting. yes, clicking the button twice does have unexpected results, but that is not relevant. don't click it twice, the bug is present after 1 click.
it's caused by pushing onto a nested array, and is still evident in your version. please re-open this ticket.
Got it-- sorry that was obscured by the other issue.
Confirmed the problem, will land a fix for this soon. Thanks guys!
Thanks for the quick turn around, I am both the guys. :D
lol, I hadn't noticed the similarity in user names... :)
Issue will be resolved by #1795
Confirmed it fixes the reported issue here:
http://jsbin.com/jicoxe/4/edit
When pushing new items into a nested array rendered by a dom-repeat with a sort attribute, duplicate items are rendered:
http://jsbin.com/fazazujamu/2/edit
(Click 'go' once, you should see items 11 and 21 duplicated in the output)
from my testing, this requires the array to be nested inside another array which is rendered with dom-repeat, and it requires the items to be added one by one, AFTER the parent item is already rendered, and must be added using this.push.