JavaScript:如何从最后到第一个反转order = []数组?

时间:2010-05-31 14:04:56

标签: javascript jquery reverse

我的js代码执行POST order.php?order [] = 1& order [] = 2& order [] = 3& order [] = 4& order [] = 5&& action = update 如何将其反转到order.php?order [] = 5& order [] = 4& order [] = 3& order [] = 2& order [] = 1&& action =更新?

JavaScript:
order=[];
//var reversed = $(this).sortable("serialize").split("&").reverse().join("&");
//var order = reversed + '&action=update'; //unfortunately it does not work so
$('#list ul').children('li').each(function(idx, elm) {
order.push(elm.id.split('-')[1])
});
$.post('order.php', {'order[]': order, action: 'update'});

HTML:

<ul>
    <li id="oreder-5">5</li>
    <li id="oreder-4">4</li>
    <li id="oreder-3">3</li>
    <li id="oreder-2">2</li>
    <li id="oreder-1">1</li>
<ul>

2 个答案:

答案 0 :(得分:4)

威尔

order.reverse();

诀窍?

答案 1 :(得分:0)

请勿使用order[]作为参数名称。如果排序对服务器端很重要,请使用order[0]order[1]等作为参数名称。