推和分类制造麻烦

时间:2018-07-24 02:53:30

标签: jquery

尝试识别第一行和最后一行,以便当其通过数组时我的排序应正确进行。以下是我的代码:

$(this).find('> tbody > tr.sortable-row').each(function(idx, row) {
  /* If we are reordering a table with some fixed rows, make sure the fixed rows
   * always follow their corresponding sortable row so they always appear together. */
  if ($(this).find('> tbody > tr.sortable-row :first')) {
    if (tableHasUnsortableRows) {
      var uniqID = $(this).attr('data-question-id'),
        correspondingFixedRow = $('tr:not(.sortable-row)[data-answer-id=' + uniqID + ']');
      correspondingFixedRow.detach().insertBefore($(this));
    }
  } else if ($(this).find('> tbody > tr.sortable-row :last')) {
    if (tableHasUnsortableRows) {
      var uniqID = $(this).attr('data-question-id'),
        correspondingFixedRow = $('tr:not(.sortable-row)[data-answer-id=' + uniqID + ']');
      correspondingFixedRow.detach().insertAfter($(this));
    }
  }
});

idsInOrder = [];
$(this).find('tr').each(function() {
  idsInOrder.push($(this).data('status'));
});

问题似乎与第一行和最后一行有关,因为我正在使用insertafter,我尝试使用if子句来确定它是否首先使用insertbefore以及是否最后使用insert和中间行,我认为insertbefore可以正常工作,我肯定

但这似乎是问题的一部分,任何想法我该如何解决

0 个答案:

没有答案