Bug Tracker

Opened 7 years ago

Closed 7 years ago

#12397 closed feature (wontfix)

Allow passing a function to .data() as an each style setter.

Reported by: gnarf Owned by: gnarf
Priority: low Milestone: None
Component: data Version: 1.8.0
Keywords: 1.9-discuss Cc:
Blocked by: Blocking:

Description (last modified by gnarf)

Example Usage:

jQuery( ".button" ).data(function( index, data ) {
    if ( data.href ) {
         // <div class="button" data-href="/">
    }
    if ( data.confirm ) {
         // etc
    }
    jQuery( this ).button();
    // return value discarded, data must remain the same object for other uses
});

The code would be a pretty simple each, and it would let you quickly inspect/alter the data object on an entire jQuery collection.

The same could NOT be done for the elems.data( "key", fn ) signature, because you want to set that key to a function...

Pull Request: https://github.com/jquery/jquery/pull/910

Change History (12)

comment:1 Changed 7 years ago by gnarf

Description: modified (diff)

comment:3 Changed 7 years ago by gnarf

Description: modified (diff)

comment:4 Changed 7 years ago by timmywil

Component: unfileddata
Keywords: 1.9-discuss added
Owner: set to gnarf
Status: newassigned

Safe to say this ticket is open.

comment:5 Changed 7 years ago by dmethvin

Type: enhancementfeature

Bulk change from enhancement to feature.

comment:6 Changed 7 years ago by mikesherov

Priority: undecidedlow

comment:7 Changed 7 years ago by mikesherov

+1, it's done already, and it's useful.

comment:8 Changed 7 years ago by ajpiano

-1, I think this is just too viscerally of an odd duck to add. It's sort of a function setter, sort of a getter... It's basically with (dataObj) { } - I don't think we need it.

comment:9 Changed 7 years ago by dmethvin

-1, It's a unique signature and there is already a way to do this, so making an exception is less compelling.

comment:10 Changed 7 years ago by Rick Waldron

-1, data() is closed

comment:11 Changed 7 years ago by gnarf

+1, Feel so dirty, voting on my own idea. It's a connivence method for plugin authors really. Or people doing large amounts of editing of the data object. I won't be offended if we pass on it though.

comment:12 Changed 7 years ago by gibson042

-1, complexity of the new signature is greater than the low cost of ad-hoc manual implementation

comment:13 Changed 7 years ago by mikesherov

Resolution: wontfix
Status: assignedclosed
Note: See TracTickets for help on using tickets.