There are other alternatives:

1. Store everything as an object in data()

  $(element).data('yourdata',{mydata1:'something,
mydata2:'something'})
  var data = $(element).data('yourdata');
  $(element).data('yourdata', $.extend(data, { mydata3:'something' });

  Then you can iterate over that object's properties.

2. Use the metadata plugin, I think it allows you to iterate over all
data stored

3. keep an 'index array'

  $(element).data('mydata1','something')
  var ind = $(element).data('mydataindex');
  $(element).data('mydataindex', ind.push('mydata1'));


All add extra overhead but it might be a worthy trade-off, and you can
write a custom function (or overwrite 'data') that handles the
extending/indexing for you.

- ricardo

On Dec 12, 1:23 am, Nick <nschub...@gmail.com> wrote:
> queue as in effect queue?  I'm not finding any documentation on queue
> except as used for effects and your sample seems to put items in a
> queue as if I had to execute things in order.  That's not what I'm
> looking for.  I need to store key/value pairs to specific elements on
> the page for nav requests and data() does this perfectly... I
> currently store they keywords I need in the data element for each list
> item and pass the list item contents to the navigation functions.  If
> I can pass a dynamic set of key/value pairs and iterate through the
> data object to get those values instead of having to know the key,
> then I can fully utilize the framework I'm working with (suppression
> flags, navigation keywords, url variables, etc.)
>
> I'd hate to have to create a new associative object and pass it when I
> can append the appropriate data to the element when the page is built
> and just pass a reference to the element.
>
> On Dec 11, 7:28 pm, Ariel Flesler <afles...@gmail.com> wrote:
>
> > You need to use $().queue() not data.
>
> > $().queue('foo',1).queue('foo',2).queue('foo',3)
>
> > Also, $().queue('foo').each() won't work because the returned data is
> > an array.
>
> > $.each($().queue('foo'), function(){ }); will work.
>
> > --
> > Ariel Fleslerhttp://flesler.blogspot.com/
>
> > On Dec 11, 7:42 pm, Nick <nschub...@gmail.com> wrote:
>
> > > Does anyone know how I can iterate through the elements stored in the
> > > data element instead of referring to them individually?
>
> > > Say I:
> > > $(someObj).data('myData1', 'Here is some text')
> > > .data('myData2', 'Here is some more text')
> > > .data('myG', 'Here is some more text');
>
> > > How could I loop through the data() object to get the key/value pairs
> > > back if I didn't know the keys?
>
> > > I tried:
> > > $(someObj).data().each(function(i, val) { alert(i + ': ' + val); });
>
> > > with no success.  I also tried variations of for loops and such.

Reply via email to