Javascript 可使用2个参数进行排序

Javascript 可使用2个参数进行排序,javascript,jquery,jquery-ui,jquery-ui-sortable,Javascript,Jquery,Jquery Ui,Jquery Ui Sortable,我正在使用sortable对一些条目进行排序。它适用于简单的位置编号,当拖放任何条目时,我可以更新这些位置编号并相应显示。但我的问题是,当用户拖动任何条目时,我还想更新另一个参数,即时间 我在这里创建,以便您能对我的问题有更多的了解 起初看起来是这样的,这很好 但当我拖动任何条目时,它只会更新位置号,而不会更新时间。我希望时间也能更新 根据Alex的建议,您应该再次调用calculateTime。唯一的变化不是再次从输入中获取数据,而是可以将输入存储在变量中并从该变量获取数据 //Here y

我正在使用
sortable
对一些条目进行排序。它适用于简单的位置编号,当拖放任何条目时,我可以更新这些位置编号并相应显示。但我的问题是,当用户拖动任何条目时,我还想更新另一个参数,即时间

我在这里创建,以便您能对我的问题有更多的了解

起初看起来是这样的,这很好

但当我拖动任何条目时,它只会更新位置号,而不会更新时间。我希望时间也能更新


根据Alex的建议,您应该再次调用calculateTime。唯一的变化不是再次从输入中获取数据,而是可以将输入存储在变量中并从该变量获取数据

//Here you set the stored variable
var stored_starttime, stored_minuteperround;

$(document).ready(function() {

  $("#timing").click(
    function() {
      //Here you set the value of the stored variable
      stored_starttime = document.getElementById("stime").value;
      stored_minuteperround = document.getElementById("rounds").value;
      calculatetime(stored_starttime, stored_minuteperround);
    }
  );
});

$("#sortable_nav").sortable({
  placeholder: "ui-state-highlight",
  helper: 'clone',
  sort: function(e, ui) {
    $(ui.placeholder).html(Number($("#sortable_nav > li:visible").index(ui.placeholder)) + 1);
  },
  update: function(event, ui) {
    var $lis = $(this).children('li');
    $lis.each(function() {
      var $li = $(this);
      var newVal = $(this).index() + 1;
      $(this).children('.sortable-number').html(newVal);
      //Here you check if the stored variables are defined
      if (stored_starttime !== undefined && stored_minuteperround !== undefined){
        calculatetime(stored_starttime, stored_minuteperround);
      }

    });
  }
});
$("#sortable_nav").disableSelection();

这是jsfiddle

,您应该能够在列表更改时再次调用
calculateTime
。如果你重构一点,就能让它很好地工作,但是即使没有重构,它也应该能工作。@AlexCorreiaSantos我想到了这一点,但是
calculateTime
的问题是它从输入框中获取值,所以如果用户分配一次时间,清除输入字段,然后拖动任何条目,它就会崩溃。这看起来是一个不错的计划,它也会工作,但我会节省这些时间数据库中的值,因此当用户返回到同一页面并拖动任何条目时,页面将不会存储任何
开始时间或任何
存储分钟错误