Questo mi è stato preoccupante per le poche ore passate ora.
Ho una tabella. In quel tavolo sto cercando il, precedente riga della tabella più vicino con un attributo dati specifici. Sto facendo questa ricerca subito dopo una corretta applicazione di jquery ordinabile. Ho provato quasi tutto e si arriva sempre con la cosa sbagliata.
Ecco quello che sto usando
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);
}
Essenzialmente, la variabile NewIndex dovrebbe afferrare la nuova posizione della riga dopo essere filtrate, menuLevel dovrebbe afferrare dell'attributo menu di livello di tale riga della tabella, e menuId è afferrando un altro attributo di dati di tale riga della tabella .
E 'specificamente alla ricerca della, precedente attributo a livello di menu più vicino nelle righe della tabella. Quindi, se una riga di tabella con un attributo livello Menu di 2 viene spostato, che sta cercando la riga della tabella più vicino con un attributo livello Menu di 1.
Lo script ordinabili piena jquery sto usando, se necessario
$(#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 > *'
});