Javascript 功能不工作,但它与另一个相同

Javascript function not working, but it's identical to another

我正在尝试将 Sortable 函数添加到多个列表。

我有这个功能:

       launchSortable : function launchSortable() {
            Sortable.create(byId('col0'), this.sortableParams);
            Sortable.create(byId('col1'), this.sortableParams);
            Sortable.create(byId('col2'), this.sortableParams);
        }

在我的 html 中,我有几个包含 class editableList 和 ID col1、col2、col3 等的列表...

我尝试用这种方式重构函数:

        launchSortableLoop : function launchSortable() {
            $editableList.each(function(index, value) {
                var id = ('col' + index);
                Sortable.create(byId(id), this.sortableParams);
            });
        },

没用...

为什么?

您确定 this.sortableParams 在范围内吗?如果你尝试这个修改会发生什么?

launchSortableLoop : function launchSortable() {
    var that = this;
    $editableList.each(function(index, value) {
        var id = ('col' + index);
        Sortable.create(byId(id), that.sortableParams);
    });
},