【发布时间】:2017-09-22 20:03:28
【问题描述】:
我有一个这样的数组:
tableObj = [
{
label: 'here',
value: 36,
element: '$(the li that this info is about)',
index: 0
},
{
label: 'are',
value: 42,
element: '$(the li that this info is about)',
index: 1
},
{
label: 'some',
value: 21,
element: '$(the li that this info is about)',
index: 2
},
{
label: 'tags',
value: 26,
element: '$(the li that this info is about)',
index: 3
}
];
当我显示数组的内容时,我会这样做:
$(".sortable-list").sortable({
axis: "y",
containment: ".sortable-list",
revert: true,
start: function(event, ui) {
var updt = ui.item.index();
tableObj.value = updt;
},
update: function(event, ui) {
var updt = ui.item.index();
tableObj.index = updt;
}
});
$( "#sortable" ).disableSelection();
其中显示的是<li> 标记在一个空的<ul class=".sortable-list"></ul> 之间。
我想要做的是拖动<li> 标签并重新排序元素,然后通过单击一个按钮,我想捕获数组的新状态。
这意味着,如果我将第二个元素移动到第一个位置,当我单击按钮时,数组将使用位置 0 中的第二个元素重新排序。
我对上面这个 jQuery 函数所做的只是设置一个新值,但我无法捕获重新排序的新数组。
有人可以帮帮我吗?先感谢您 ! :)
【问题讨论】:
标签: javascript jquery html arrays