views:

27

answers:

1

I'm trying to build an array structured like

[ 
  [num,
    [num, num num]],
  [num,
    [num, num]],
]

but I get [num,num,num,num,num,num,num] =(

code here: http://jsfiddle.net/WRppV/4/

the problem is that I'm trying to send the var 'x' as data in an AJAX update function that jQueryUI uses for sortable. And it needs to be the array structure above. =\

I'm using the http://jqueryui.com/demos/sortable/#connect-lists kind of sorting.

So, normally I would just to $j(list selector).sortable('serialize')

but because I have two lists I tried this $j(selector1,selector2).sortable('serialize') which is what you do for sorting two lists as in the example. But when the ajax request is made, it only sends the updated list. Which would be fine if I had tons of processing power. but I need the list, and which list it belongs to.

Whats really interesting is that my server says the war is getting sent as

 "content"=>"215,207"

but that doesn't even include the section_id I should be getting something similar to

["141", ["203", "206", "204", "205"],
 "142", ["215", "207"]]

(numbers and structure from chrome when I run the script from the link on my webpage)

my sortable js:

$j("<%= @sortable_contents %>").sortable({
    connectWith: '.section-content',
    axis: 'y',
    zIndex: 1003,
    cursor: 'crosshair',
    update: function(){
        d = $j("#sort_sections > li").map(function(index, element){
            return [element.id.replace(/[a-z]+_/,""), [
                $j(element).find("li.content").map(function(subindex, subelement){
                    return subelement.id.replace(/[a-z]+_/,"");
                }).get()]];
        }).get();
        alert(d)
              $j.ajax({
                type: 'post',
                data: {'content': d},//$j("<%= @sortable_contents %>").sortable('serialize'),//
                dataType: 'script',
                complete: function(request){
                  $j('#sort_contents').effect('highlight');
                  },
                url: '/contents/sort_contents'})
              }
});
+1  A: 

This is nested. Don't listen to alert, try console.log instead.

In chrome, this gets logged out as this: alt text

Squeegy
the problem is that I'm trying to send the var 'x' as data in an AJAX update function that jQueryUI uses for sortable.
DerNalia
There is no problem, as @Squeegy says. You are only getting bad output, not bad structure. The variable `x` is fine.
Amadan
I added some details, to help further explain my problem.
DerNalia