Zostało to niepokoi mnie przekazany kilku godzin teraz.
Mam tabeli. Wewnątrz tej tabeli szukam najbliższego, poprzedniego wiersza tabeli z określonym atrybutem danych. Robię to szukanie tuż po udanym wykorzystaniu jquery sortable. Próbowałem prawie wszystkiego i zawsze wyjdzie z niewłaściwej rzeczy.
Oto, czego używam
var newIndex = ui.item.index();
var menuLevel = parseInt($(#menu-table).find([data-menu-nesting=' + newIndex + ']).attr(data-menu-level));
var menuId = $(#menu-table).find([data-menu-nesting=' + newIndex + ']).attr(data-menu-id);
if (menuLevel == 2) {
var findAboveRowName = $(.menu-table-rows[data-menu-nesting=' + newIndex + ']).prev(.menu-table-rows).data(menu-level,1).attr(data-menu-name);
alert(findAboveRowName);
}
if (menuLevel == 3) {
var findAboveRowName = $(.menu-table-rows[data-menu-nesting=' + newIndex + ']).prev(.menu-table-rows).data(menu-level,2).attr(data-menu-name);
alert(findAboveRowName);
}
Zasadniczo, zmienna „newIndex” ma chwycić nową pozycję rzędu po sortowane, menuLevel ma chwycić danych atrybutu „Menu-level” w tym wierszu tabeli, a menuId jest chwytając inny atrybut danych tego wiersza tabeli ,
To specjalnie szukając najbliższego, poprzedniego poziomu menu atrybut w wierszach tabeli. Więc jeśli wiersz tabeli z atrybutem menu poziomu 2 jest przesuwana, to patrząc na najbliższy wiersza tabeli z atrybutem menu na poziomie 1.
Pełne jquery sortable skrypt używam w razie potrzeby
$(#sortable).sortable({
update: function(event, ui) {
var serial = $('#sortable').sortable('serialize');
var newIndex = ui.item.index();
var menuLevel = parseInt($(#menu-table).find([data-menu-nesting=' + newIndex + ']).attr(data-menu-level));
var menuId = $(#menu-table).find([data-menu-nesting=' + newIndex + ']).attr(data-menu-id);
if (menuLevel == 2) {
var findAboveRowName = $(.menu-table-rows[data-menu-nesting=' + newIndex + ']).prev(.menu-table-rows).data(menu-level,1).attr(data-menu-name);
alert(findAboveRowName);
// $.post(./menu-controller.php, { adjustParent: true, id: menuId, parent: findAboveRowName });
}
if (menuLevel == 3) {
var findAboveRowName = $(.menu-table-rows[data-menu-nesting=' + newIndex + ']).prev(.menu-table-rows).data(menu-level,2).attr(data-menu-name);
alert(findAboveRowName);
// $.post(./menu-controller.php, { adjustParent: true, id: menuId, parent: findAboveRowName });
}
$.ajax({
url: ./menu-controller.php,
type: post,
data: serial,
success: function() {
$(#sortable).load(./menu-manager.php #menu-table, function() {
$.get('./menu-admin.js');
});
},
error: function(){
alert(A problem occurred when moving this menu item. Please try again or contact support.);
}
});
},
handle:'.move-item',
connectWith:'#menu-table',
placeholder: highlight,
containment: parent,
revert: true,
tolerance: pointer,
items: 'tbody > *'
});