I have this simplified version of my webpage (its a mess IRL):
<li id=section1 class=sortable_section>
<header>
<ul id=container1>
<li id=item1 class=sortable_item>
<li id=item2 class=sortable_item>
</container
</section
<li id=section2 class=sortable_section>
<header>
<ul id=container2>
<li id=item3 class=sortable_item>
<li id=item4 class=sortable_item>
<li id=item5 class=sortable_item>
</container>
</section>
So, I can do $j("container1").sortable('serialize') which creates an array of the ids of all the containing li's. so I would get ["item1", "item2"] for container1.
How do I make an array that looks like this:
[
["section1", ["item1", "item2"]],
["section2", ["item3", "item4", "item5"]]
]
This is what ive been trying: but it doesn't work
d = $j.makeArray(
$j('.sortable_section').each(function(i){
[$j(this).attr("id"),
$j.makeArray($j.map($j("#"+$j(this).attr("id")+" .sortable_item"), function(s,j){
return ($j(s).attr("id"));
}))]
}));
But it returns the entire objects, rather than just the ids....
EDIT: as per one of the answers' suggestions, this is now what I have
d = $j(".sections > li").map(function(index, element){
return [$j(element).attr('id'),
$j("#"+$j(element).attr('id') + " .content").map(function(subindex, subelement){
return $j(subelement).attr('id');
}).toArray()];
}).toArray();
but I get this error
TypeError: Result of expression near '...}).toArray()]...' [undefined] is not a function.
When I do alerts on $j(element).attr('id') and $j(subelement).attr('id') I get the correct ids