#12786 closed bug (fixed)
jQuery removeData() doesn't work , it seems like a bug
Reported by: | Owned by: | Rick Waldron | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.8.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
when I use the code follow:
<script> var a = {}; $(a).data('a-a', 1); $(a).data('b-b', 2); add data to cache
$(a).removeData(['a-a','b-b']); it dosen't work $(a).removeData('a-a b-b'); it works </script> and I think the reason is here in data.js :
if ( !jQuery.isArray( name ) ) {
try the string as a key before any manipulation if ( name in thisCache ) {
name = [ name ];
} else {
split the camel cased version by spaces unless a key with the spaces exists name = jQuery.camelCase( name ); if ( name in thisCache ) {
name = [ name ];
} else {
name = name.split(" ");
}
}
}
for ( i = 0, l = name.length; i < l; i++ ) {
delete thisCache[ name[i] ];
}
when the param name is an array , we don't use jQuery.camelCase( name ) ,so we can't remove the data.
Change History (5)
comment:1 Changed 11 years ago by
comment:2 Changed 11 years ago by
Owner: | set to lovesueee@… |
---|---|
Status: | new → pending |
The only reason we support .data()
on plain objects is so that events work on plain objects. Internally we never need the camel-casing that .data()
provides. What is the use case there, versus just setting a property on the object?
comment:3 Changed 11 years ago by
Owner: | changed from lovesueee@… to Rick Waldron |
---|---|
Status: | pending → assigned |
comment:4 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Brute force property removal when removeData([a,b,c]). Fixes #12786
Changeset: 812c6087ada4a6383fd2e033d04648ec0f6691ea
when I use the code follow:
and I think the reason is here in data.js :
when the param name is an array , we don't use jQuery.camelCase( name ),so we can't remove the data.