[jQuery] Re: Cookie Plugin - Trying to get the values of elements in the array of cookies.

2007-08-30 Thread Pyrolupus

> I'm using the cookie plugin.  And, I have created 4 cookies with it
> and they are named [Expanded[]].
>
> I also keep a count of the number of cookies that have been created
> and the name of this cookie is [onExpandCount].
>
> How do I loop through these cookies?
>
> function expandMenuUsingCookie() {
> for (var index=0;index<$.cookie('onExpandCount');index++) {
> //console.log(index);
> 
> YAHOO.widget.TreeView.getNode('menu',$.cookie('Expanded['+index
> +']')).toggle();
> }
>
> }
>
> There's something wrong with this line right about where I try to get
> the value of the cookie:
> YAHOO.widget.TreeView.getNode('menu',$.cookie('Expanded['+index
> +']')).toggle();
You are mixing up your quotes.  Too make this work (did not test
syntax or library) and also make it a tad more readable, get your node
index before you try to access the node:

nodeIdx = $.cookie('Expanded')[index]);
...getNote('menu', $.cookie(nodeIdx))...

Note the movement of the square brackets to the outside of
$.cookie().  Having just looked through the source for
jquery.cookie.js, though (I haven't used the plugin before), I'm not
sure that it returns an array of "subcookies."  You may need to
experiment with split()ing the return value to get what you're after.

Also, your loop will perform much faster if you store your array
length before starting the loop so that it's not looked up each
iteration (e.g., var arrLen = arr.length; for (var i = 0; i < arrLen; i
++) {}).[1]

Pyro

[1] http://www.thinksharp.org/?p=83



[jQuery] Re: Cookie Plugin - Trying to get the values of elements in the array of cookies.

2007-08-30 Thread Benjamin Sterling
have you tried wrapping $.cookie('onExpandCount') in a
parseInt($.cookie('onExpandCount'))?

Also

On 8/30/07, cfdvlpr <[EMAIL PROTECTED]> wrote:
>
>
> I think this is actually more of a problem with Javascript syntax than
> it is with the cookie plugin, but any help would be much appreciated.
>
>


-- 
Benjamin Sterling
http://www.KenzoMedia.com
http://www.KenzoHosting.com


[jQuery] Re: Cookie Plugin - Trying to get the values of elements in the array of cookies.

2007-08-30 Thread cfdvlpr

I think this is actually more of a problem with Javascript syntax than
it is with the cookie plugin, but any help would be much appreciated.