Вопрос

I want to add GUID as id of the li DOM element like below:

<ul>
  <li id="item-{78C9267C-1A41-BCCD-392D-06DA2C4198B1}"></li>
</ul>

so that I can serialize this using jquery sortable. Currently following code is resulting in JSON.parse invalid character error:

$("ul").sortable({
  update:function() {
    var sorted = $(this).sortable( "serialize" );
  }
}); 
Это было полезно?

Решение

Use .sortable( "serialize" , { expression : /(.+)-{(.+)}/ })

Другие советы

serialize will not build a valid JSON:

Serializes the sortable's item ids into a form/ajax submittable string. Calling this method produces a hash that can be appended to any url to easily submit a new item order back to the server.

To build up a valid JSON starting from your sorted elements you can use stringify your sortable elements get as string array using toArray, code:

$("ul").sortable({
    update: function () {
        var sorted = JSON.stringify($(this).sortable('toArray'));
        console.log(sorted)
    }
});

Demo: http://jsfiddle.net/IrvinDominin/Qwx2U/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top