#8047 closed bug (invalid)
.data function bug
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | 1.5 |
Component: | data | Version: | 1.5rc1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
It illustraed on jsfiddle http://jsfiddle.net/ZagJA/ :
var q = { boolField: true }; $(q).data("boolField", "true"); $("#result").append(JSON.stringify(q));
this code on 1.4.4 or 1.5 beta 1 produce result:
{"boolField":"true"}
but in on 1.5 RC 1 it is produce:
{"boolField":true,"jQuery03474161645863205":{"boolField":"true"}}
this is wrong...
PS: Also 1.5RC1 ajax with 'json' request/response type return parseerror on valid json.
Change History (6)
comment:1 Changed 12 years ago by
Owner: | set to [email protected]… |
---|---|
Status: | new → pending |
comment:2 Changed 12 years ago by
Component: | unfiled → data |
---|
comment:3 Changed 12 years ago by
Milestone: | 1.next → 1.5 |
---|---|
Priority: | undecided → low |
Resolution: | → invalid |
Status: | pending → closed |
Thanks for taking the time to contribute to the jQuery project by writing a bug report.
This isn't a bug but the intended behavior.
Actually the behavior introduced with 1.4.3 was a regression compared to the behavior of earlier jquery versions. In jQuery 1.4.3/1.4.4 .data() on a plain js object did a destructive operation, in the sense that it overwrote existing properties.
You can compare the behavior of jQuery over different versions with this test case. This test shows how the behavior in 1.4.3/1.4.4 has unwanted side-effects.
If you want to change properties directly on an object its much easier and faster to do q.boolField = something
instead of using .data()
.
comment:4 Changed 12 years ago by
Uff... Thanks for explain!
Note: Current version of jquery.datalink plugin designed for version 1.4.3 (works both with 1.4.4 and 1.5b1), uses .data() method for changing object properties (with events). But, of course, this is issue of datalink plugin.
comment:5 Changed 12 years ago by
afaik this is known to the datalink team. datalink is still in beta and likely to undergo structural changes in which problems like this are surely going to be addressed.
comment:6 Changed 12 years ago by
Current datalink builds provide the .setField() method to use, rather than .data(). However the problem of serialization of the object being broken unfortunately remains, and is not due to datalink itself. It is independent of datalink.
Please file a separate ticket for the ajax error.