backbone-forms icon indicating copy to clipboard operation
backbone-forms copied to clipboard

Pass id through to child list items, and iterate index for each item.

Open rjmackay opened this issue 11 years ago • 2 comments

Making it easier to work with list items by giving them unique ids.

rjmackay avatar Jun 26 '14 03:06 rjmackay

+1

fonji avatar Jul 07 '14 15:07 fonji

I haven't explicitly tested it, but I think that this has problems with lists that are meant to be sorted or re-ordered, such as this plugin

If you have 4 items such as this:

[{id:1},{id:2},{id:3},{id:4}]

and you move the last item to the front of the array

[{id:4},{id:1},{id:2},{id:3}]

Your ids (wth the implied order because you're using the length attribute for id) are now confusing.

Even worse, if you now remove the last item

[{id:4},{id:1},{id:2}]

but then add a new one

[{id:4},{id:1},{id:2},{id:4}] //length is 4 again

We have duplicate IDs.

I do not think items.length should be used to generate the id. Instead, I would recommend using the view's cid attribute.

Is there a specific reason you needed the index in the id string? If so, is there a reason you can't index the item against list.items?

iabw avatar Aug 28 '14 17:08 iabw