Ticket #7323 (closed enhancement: fixed)
Allow removing multiple data keys at once with $.fn.removeData
| Reported by: | rmurphey@… | Owned by: | gnarf |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.7 |
| Component: | data | Version: | 1.4.3 |
| Keywords: | removeData,1.7-discuss | Cc: | |
| Blocking: | Blocked by: |
Description
I just saw some code in Wijmo that had a string of chained removeData() calls, and it occurred to me there should probably be a way to remove multiple data keys at once. Not sure whether this is a worthwhile addition (I know there are better ways they could have done this to avoid needing to remove one key at a time), but if so, I'd suggest an API that accepts either a string containing a single key (which is what currently works) or an array of keys.
Change History
comment:1 Changed 3 years ago by SlexAxton
- Keywords removeData added
- Status changed from new to open
- Component changed from unfiled to data
comment:2 follow-up: ↓ 3 Changed 3 years ago by anonymous
Yes :) Didn't want to submit one unless it was something people liked.
comment:3 in reply to: ↑ 2 Changed 3 years ago by rmurphey
Replying to anonymous:
Yes :) Didn't want to submit one unless it was something people liked.
Sorry, that was me, I wasn't logged in.
comment:6 Changed 2 years ago by john
- Priority changed from undecided to low
- Milestone set to 1.next
We should consider this for 1.7.
comment:7 Changed 2 years ago by john
- Keywords removeData,1.7-discuss added; removeData removed
Nominating ticket for 1.7 discussion.
comment:10 Changed 2 years ago by rmurphey
Per the discussion on the pull request ( https://github.com/jquery/jquery/pull/77) there needs to be a decision as to the API. If we go with a single string, which is consistent with existing APIs ...
$('#foo').removeData('a b c');
... then we make it impossible to remove a key with a space in it. If we go with an array, as I did in the pull request ...
$('#foo').removeData([ 'a', 'b', 'c' ]);
... then we can allow the removal of any valid key, either one or many at a time.
I have no horse in this race; I can see the merits of both solutions.
comment:11 Changed 2 years ago by timmywil
+1, In favor, but I don't think space-separated by itself is enough.
comment:12 Changed 2 years ago by ajpiano
+1, I don't know if we want to break space-separated keys for 1.7 - I like the array, even thought it's "inconsistent" with other aspects of the API
comment:13 Changed 2 years ago by john
+1, Let's do this.
comment:14 Changed 2 years ago by scott.gonzalez
+1, space delimited string, like everything else
comment:15 Changed 2 years ago by rwaldron
Scott, keep in mind that data properties can be any valid string
https://github.com/jquery/jquery/pull/77#issuecomment-665309
illustrated here:
http://jsfiddle.net/rwaldron/Bt4nK/
But then again, we could always just say that strings with spaces are prohibited
comment:16 Changed 2 years ago by jzaefferer
+0
comment:17 Changed 2 years ago by dmethvin
- Priority changed from low to blocker
- Milestone changed from 1.next to 1.7
comment:20 Changed 21 months ago by Corey Frang
- Status changed from assigned to closed
- Resolution set to fixed
Landing pull request 512. 1.7 - removeData now takes space separated lists and arrays of keys - Fixes #7323.
More Details:
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Seems fair. Any desire to write a patch? :D