Esto me ha estado preocupando por las pocas horas pasaron ahora.
Tengo una tabla. Dentro de esa mesa que estoy buscando la, fila de la tabla anterior más cercana con un atributo de datos específico. Estoy haciendo esta búsqueda justo después de un uso exitoso de sortable jQuery. He intentado casi todo y que siempre surge con lo que no debía.
Esto es lo que estoy 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);
}
En esencia, la variable NewIndex se supone que agarrar la nueva posición de la fila después de haber sido ordenados, menuLevel se supone que agarrar el atributo de datos menú de nivel de esa fila de la tabla, y MenuID es agarrar otro atributo de datos de esa fila de la tabla .
Se ve específicamente para el, anterior atributo de nivel de menú más cercano en las filas de la tabla. Así que si una fila de la tabla con un atributo de nivel de menú 2 se mueve, que está buscando la fila de tabla más cercana con un atributo de nivel de menú 1.
La secuencia de comandos se puede ordenar completa jQuery que estoy usando, si es necesario
$(#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 > *'
});