I've recently updated my setup to jquery 1.2.3 and am using sortables from UI
1.5b. I couldn't get the serialize option to work either - something to do
with the way options are parsed - by default it tries to match the ids of
all sortable items to (/(.+)[-=_](.+)/) so I guess your IDs need to have a
-, =, or _ in them for it to work(?). Anyway, I've written a function to
help me do what I want:

<script>
  $(document).ready(function(){
    $("#myList").sortable({
        update : function(e, ui)
        {
            serialize("#myList");
        }
    });
  });
function serialize(s)
{
    var str = [];
    var key = 'myKey[]=';
    var delimiter = '&'
    $(s + "> *").not('.ui-sortable-helper').each(function() {
        str.push(key+this.getAttribute('id'));
    });
    $("#serialized").html(str.join(delimiter));
};
  </script>
  <style>ul { list-style: none; }
li { background: #727EA3; color: #FFF; width: 100px; margin: 5px; font-size:
10px; font-family: Arial; padding: 3px; }</style>
</head>
<body>

<ul id="myList">
  <li id="11">Item 1</li>
  <li id="23">Item 2</li>
  <li id="33">Item 3</li>
  <li id="44">Item 4</li>
</ul>

<p id="serialized"></p>

The serialize function above grabs all the children of the container apart
from the helper $("#myList> *).not('.ui-sortable-helper') and stuffs their
id attributes into an array. I've added something to display the results
below the list. Adjust the key and delimiter variables in the body of the
function to make a hash out of them to your liking.


chrille112 wrote:
> 
> I'm stuck! I have followed the examples there is, but I can't make this
> work. My code below just generates an empty alert box:
> 
> <script>
>   $(document).ready(function(){
>     $("#myList").sortable({
>               update : function(e, ui)
>               {
>                       serialize("#myList");
>               }
>       });
>   });
> 
> function serialize(s)
> {
>       serial = jQuery.SortSerialize(s);
>       alert(serial.hash);
> };
>   </script>
>   <style>ul { list-style: none; }
> li { background: #727EA3; color: #FFF; width: 100px; margin: 5px;
> font-size: 10px; font-family: Arial; padding: 3px; }</style>
> </head>
> <body>
> 
> <ul id="myList">
>           <li id="11">Item 1</li>
>           <li id="23">Item 2</li>
>           <li id="33">Item 3</li>
>           <li id="44">Item 4</li>
> </ul>
> 

-- 
View this message in context: 
http://www.nabble.com/Sortserialize-returns-nothing%21-tp15362349s27240p15459595.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to