【发布时间】:2014-07-13 00:02:00
【问题描述】:
我正在尝试重新排序 jquery 中可排序的列表元素,当它根据它们在列表中的顺序创建时。
var CACHES = ["WayBack Machine", "Google Cache", "Coral CDN"];
var HTML = ["Google Cache", "WayBack Machine", "Coral CDN"];
$("#sortable").sortable({
stop: function(event, ui) {
console.log("New position: " + ui.item.index());
},
change: function(event, ui) {
// When the item postion is changed while dragging a item, I want it's position
console.log("New position: " + ui.item.index());
},
create: function(event, ui) {
console.log("Sortable Created");
var ul = $('#sortable');
var li = ul.children('li').get();
li.sort(function(a,b) {
$(a).attr('id')
var value = CACHES.indexOf($(a).attr('id')) < CACHES.indexOf($(b).attr('id')) ? 1 : -1
console.log(value)
return value
});
ul.append(li);
}
});
var HTML 是它们在页面 HTML 中的顺序。 var CACHES 是我要放入它们的顺序。它似乎确实对元素重新排序,但不正确。
【问题讨论】:
标签: javascript jquery jquery-ui