Skip to main content

Bug Tracker

Side navigation

#12786 closed bug (fixed)

Opened October 24, 2012 09:40AM UTC

Closed October 24, 2012 06:13PM UTC

Last modified November 02, 2012 04:12PM UTC

jQuery removeData() doesn't work , it seems like a bug

Reported by: lovesueee@me.com Owned by: rwaldron
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.

Attachments (0)
Change History (5)

Changed October 24, 2012 09:44AM UTC by lovesueee@me.com comment:1

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.

Changed October 24, 2012 01:48PM UTC by dmethvin comment:2

owner: → lovesueee@me.com
status: newpending

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?

Changed October 24, 2012 05:15PM UTC by rwaldron comment:3

owner: lovesueee@me.comrwaldron
status: pendingassigned

Changed October 24, 2012 06:13PM UTC by rwaldron comment:4

_comment0: Brute force property removal when removeData([a,b,c]). Fixes #12786\ \ Signed-off-by: Rick Waldron <waldron.rick@gmail.com> \ Changeset: 812c6087ada4a6383fd2e033d04648ec0f6691ea1351102404867233
resolution: → fixed
status: assignedclosed

Brute force property removal when removeData([a,b,c]). Fixes #12786

Changeset: 812c6087ada4a6383fd2e033d04648ec0f6691ea

Changed November 02, 2012 04:12PM UTC by rwaldron comment:5

#12836 is a duplicate of this ticket.