Opened 10 years ago
Closed 10 years ago
#14111 closed bug (notabug)
.data(obj) sets data in weird way that ignores next .data(key,value) call
Reported by: | anonymous | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 2.0.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Steps to reproduce: Go to http://jsbin.com/uzecoq/5 Click on the title three times slowly. The first click should do nothing.
Expected result: The alerted message should appear on the second click.
Observed result: The alerted message does not appear until the third click!
The following is the incorrect code: obj.data({'foo':false}); obj.data('foo',true); obj.data('foo'); returns false instead of true!!
However if I do either of these two it works great: obj.data({'foo':false}); obj.data('foo',true); obj.data('foo',true); Have to assign twice for it to stick.. obj.data('foo'); returns true --OR-- obj.data('foo',false); Don't use .data(obj) and there is no issue! obj.data('foo',true); obj.data('foo'); returns true
Change History (3)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
My bad.
Thanks for getting back to me so fast :).
I can't close the ticket, but I feel satisfied that this resolved the issue.
comment:3 Changed 10 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
The examples using "foo" should work with no problem. The issue is that you've used a hyphenated form of a name when setting the data object in the code sample. You always need to use the W3C camelCased form when setting data directly.
http://jsbin.com/uzecoq/10/edit
It's mentioned here:
Since your call to
.data()
*explicitly* requests the dashed form, that value is returned to you even though the normalized camelCased value has been changed by a subsequent call.