如何将 "inject" 变量转换为匿名函数

How to "inject" a variable into an anonymous function

我有以下 jQuery (ui) 代码:

    function initSortable() {
    var placeholderClass = "ui-state-highlight";
    var movement; /* = {'id': 0, 'from': 0, 'to': 0};*/
    setPlaceholderClassHeight(placeholderClass);
    $(".listTable td").each(function () {
        $(this).css("width", $(this).width());
    });
    $('.listTable tbody').sortable({
        placeholder: placeholderClass,
        forcePlaceholderSize: true,
        axis: "y",
        cursor: "grab",
        opacity: 0.8,
        start: function (event, ui) {
            ui.item.toggleClass("highlight");
            movement.id = ui.item.data('id');
            movement.from = ui.item.data('id');
            console.log(ui.item.index());
            console.log(ui.item.data('id'));
        },
        stop: function (event, ui) {
            ui.item.toggleClass("highlight");
        },
        update: function (event, ui) {
            console.log(ui.item.index());
            movement.to = ui.item.index();
            console.log(movement);
        }
    });
}

它不起作用,因为 movement 在分配给 start/stop/update 的函数中未知。 如何使用和更改移动变量?

movement 在正确的位置声明,它应该更新。它没有更新,因为它是 undefined。声明 var movement = {} 并检查