tjyoung
asked on
Possible to remove duplicates from a selectlist populated by json?
Hi,
I have a selectlist that is populated by json. The issue I'm having is I get duplicates in my selectlist and I'm hoping I can remove them as the selectlist loads.
I have a fiddle to show you what I mean:
See Fiddle
The actual vehicles aren't really 'duplicates' but since I'm only showing a select amount of the supplied data (name and basic style) they appear duplicate in the select.
I came across juery.unique() but not sure if that would work... or how to apply it in this instance. Any help would be appreciated.
Thanks!
I have a selectlist that is populated by json. The issue I'm having is I get duplicates in my selectlist and I'm hoping I can remove them as the selectlist loads.
I have a fiddle to show you what I mean:
See Fiddle
The actual vehicles aren't really 'duplicates' but since I'm only showing a select amount of the supplied data (name and basic style) they appear duplicate in the select.
I came across juery.unique() but not sure if that would work... or how to apply it in this instance. Any help would be appreciated.
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thats fabulous. Never would have figured that out. Many thanks!
For example:
<option value="200420764">ATS Luxury 4dr Sedan</option>
<option value="200420763">ATS Luxury 4dr Sedan</option>
<option value="200420762">ATS Luxury 4dr Sedan</option>
While the text is the same, the value is different.
Notice this in your JSON:
"id": 200420764,
"name": "Luxury 4dr Sedan (3.6L 6cyl 6A)",
and
"id": 200421837,
"name": "Luxury 4dr Sedan (3.6L 6cyl 6A)",
Because the ID is the key and it is unique, using something like juery.unique() would not help.