jquery sortable with regexp
I am try开发者_如何学JAVAing to figure out the right regexp to match on list item id's.
For example:
<ul id="MyList" class="connectedSortable">
<li id="id=1-32">Item 1</li>
<li id="id=2_23">Item 2</li>
<li id="id=3">Item 3</li>
<li id="id=4">Item 4</li>
<li id="id=5">Item 5</li>
<li id="id=6">Item 6</li>
</ul>
On the serialize method, I want it to pull everything after the equal sign (=). For example, for the first item I need the id to be 1-32, for the second I need it to be 2_23.
$(function () {
$("#MyList, #OtherList").sortable({
connectWith: '.connectedSortable',
update: function () {
$("#MyListOrder").val($("#MyList").sortable('serialize', { regexp: '/(.+)[=](.+)/)' }));
}
}).disableSelection();
});
I tried the above, but that didn't quite work. My regexp expression is wrong and I don't know what it should be. Ideas?
UDPATE: Instead of using the serialize method, I decided to use toArray. That way I get the whole ID and can rip out the part I don't want server side.
According to the specs, the option should be named "expression", and you don't need the /.../
in the string, unless you pass a regular expression. This works:
.sortable('serialize', { expression: '(.+)=(.+)' })
or:
.sortable('serialize', { expression: /(.+)=(.+)/ })
Working Example: http://jsbin.com/oqejo3/2
精彩评论