🌐 AI搜索 & 代理 主页
Skip to content

Commit d36d224

Browse files
committed
Implemented .data() to get the entire data object. Closes #4284
1 parent 8e54b16 commit d36d224

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/data.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jQuery.extend({
2323
if ( data !== undefined )
2424
jQuery.cache[ id ][ name ] = data;
2525

26+
if(name === true) return jQuery.cache[ id ]
27+
2628
// Return the named cache data, or the ID for the element
2729
return name ?
2830
jQuery.cache[ id ][ name ] :
@@ -98,6 +100,8 @@ jQuery.extend({
98100

99101
jQuery.fn.extend({
100102
data: function( key, value ){
103+
if(typeof key === "undefined" && this.length) return jQuery.data(this[0], true);
104+
101105
var parts = key.split(".");
102106
parts[1] = parts[1] ? "." + parts[1] : "";
103107

test/unit/data.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ test("jQuery.data", function() {
1515
});
1616

1717
test(".data()", function() {
18+
expect(1);
19+
20+
var div = jQuery("#foo");
21+
div.data("test", "success");
22+
isObj( div.data(), {test: "success"}, "data() get the entire data object" )
23+
})
24+
25+
test(".data(String) and .data(String, Object)", function() {
1826
expect(22);
1927
var div = jQuery("#foo");
2028
equals( div.data("test"), undefined, "Check for no data exists" );

0 commit comments

Comments
 (0)