Este foi me incomodando há poucas horas se passaram agora.
Eu tenho uma tabela. Dentro dessa mesa eu estou procurando o, linha de tabela mais próximo anterior com um atributo de dados específico. Eu estou fazendo esta pesquisa logo após um uso bem sucedido de classificáveis jquery. Eu tentei quase tudo e ele sempre vem com a coisa errada.
Aqui está o que eu estou 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);
}
Essencialmente, a variável NewIndex é suposto para pegar a nova posição da linha depois de ser ordenado, menuLevel é suposto para pegar o atributo menu de nível daquela linha da tabela, e menuId está agarrando outro atributo de dados de que linha da tabela .
É especificamente procurando o, atributo de nível de menu mais próximo anterior nas linhas da tabela. Então, se uma linha da tabela com um atributo de nível de menu 2 é movido, ele está olhando para a linha da tabela mais próxima com um atributo de nível de menu 1.
O script classificáveis completa jquery eu estou usando, se necessário
$(#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 > *'
});