Skip to main content

Bug Tracker

Side navigation

#12397 closed feature (wontfix)

Opened August 25, 2012 10:36PM UTC

Closed October 29, 2012 05:31PM UTC

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

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

Attachments (0)
Change History (12)

Changed August 25, 2012 10:38PM UTC by gnarf comment:1

description: Example Usage: \ \ {{{ \ jQuery( ".button" ).data(function( index, data ) { \ if ( data.href ) { \ // <div class="button" data-href="/"> \ } \ if ( data.confirm ) { \ // etc \ } \ jQuery( this ).button(); \ }); \ }}} \ \ 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...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...

Changed August 25, 2012 10:56PM UTC by gnarf comment:2

description: 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...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

Changed August 27, 2012 02:30PM UTC by timmywil comment:3

component: unfileddata
keywords: → 1.9-discuss
owner: → gnarf
status: newassigned

Safe to say this ticket is open.

Changed September 09, 2012 01:10AM UTC by dmethvin comment:4

type: enhancementfeature

Bulk change from enhancement to feature.

Changed September 09, 2012 05:35AM UTC by mikesherov comment:5

priority: undecidedlow

Changed October 14, 2012 10:38PM UTC by mikesherov comment:6

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

Changed October 17, 2012 04:08PM UTC by ajpiano comment:7

-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.

Changed October 17, 2012 04:37PM UTC by dmethvin comment:8

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

Changed October 17, 2012 04:41PM UTC by rwaldron comment:9

-1, data() is closed

Changed October 22, 2012 05:47PM UTC by gnarf comment:10

+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.

Changed October 22, 2012 05:49PM UTC by gibson042 comment:11

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

Changed October 29, 2012 05:31PM UTC by mikesherov comment:12

resolution: → wontfix
status: assignedclosed