SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using the $$ (double dollar) function and sortables...

    Whoa I am stumped.

    long story short... using mootools and the Sortables feature. No prob there. The problem I am having, is that I am going to have multiple lists on the same page (and wont know how many lists).

    So I use $$ and get an array of all the lists. (they are all named "list1","list2", and so on).

    Then I loop through the array and create a Sortable instance for each one.... this is where my problem begins.

    I am pretty sure that each instance of Sortables has to be assigned it's own unique variable. So I tried using an array. But the array doesnt work. I get an error asking for a semicolon right before the declaration.

    Im stumped in how to get it assigned to a unique variable name on each itteration, and why an array wont work?

    Is there a way I can make a string with the iteration number in it, and then create a variable with the same name as the value of the string? Is there an easier approach? Javascript is an unfamiliar beast with me, most of my developer years have been tackling php and other server side languages.

    anyways.. here is what i have right now... and the whole "var mySortables[i]" isnt working..

    Code:
    var z=$$('ul[id^=list]');	
    for(i=0;i<z.length;i++) {
         var mySortables[i] = new Sortables('z[i]',{
    			clone: true,	
    			revert: true,
    			handle:'div.rowGreyInner',
    			opacity: 0,
    			onComplete: function(){
    					var myString = mySortables[i].serialize(); 
    			} 
    	});
     }

    Would anyone be kind enough to point me in a direction, or something I can look up?

    Thanks for your time!

    - Ryan

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its funny, you can look at something for hours... and see nothing..

    You take 15 minutes off to type a post to a forum, come back, and see the problem staring you in the face.

    I was calling the z[i] as a string instead of a variable. Duh.

    Although... I am still curious how I could name a variable based off a string... I know in php it would be something like...

    Code:
    $x="foo";
    $$x="blah";
    echo $foo; //prints "blah"
    is there an equivalent in javascript?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •