【问题标题】:jQuery UI sortables - get handle on dropped itemjQuery UI sortables - 处理丢弃的项目
【发布时间】:2012-01-18 12:19:15
【问题描述】:

我在 UI 1.8.6 中使用 this hack 进行了这项工作,但我似乎无法让它在 1.8.17 中工作。

  • 我想将列表中的项目拖到可排序的列表中。
  • 删除后项目应保留在源列表中(以便可以添加 n 次)
  • 当我将项目放入可排序中时,我想获取可排序中已放置项目的实例的句柄。

在 sortable 的接收方法中:

receive: function(e, ui){
    // ui.item is the original dragged item, not the clone that gets created when dropped
    // ui.helper is a separate clone of the dragged item, it does not get inserted into the sortable
}

所以问题是,我如何处理插入的项目?在调用 receive 时,该项目似乎尚未插入(或创建)。对 jquery UI 进行了更改还是我遗漏了什么?

这是我的代码:

$('form').sortable({
    placeholder: "placeholder",
    forcePlaceholderSize: true,
    receive: function (ev, ui) {
        // need handle on dropped item here. ui.item and ui.helper are not it
    }
});


$('.draggableTings').draggable({
    helper: "clone"
    , appendTo: "body"
    , revert: "invalid"
    , connectToSortable: "form"
});

谢谢

【问题讨论】:

    标签: jquery jquery-ui jquery-ui-sortable


    【解决方案1】:

    替换这个

    _uiHash: function(inst) {
        var self = inst || this;
        return {
            helper: self.helper,
            placeholder: self.placeholder || $([]),
            position: self.position,
            originalPosition: self.originalPosition,
            offset: self.positionAbs,
            item: self.currentItem,
            sender: inst ? inst.element : null
        };
    }
    

    有了这个

    _uiHash: function(inst) {
        var self = inst || this;
        return {
            helper: self.helper,
            placeholder: self.placeholder || $([]),
            position: self.position,
            originalPosition: self.originalPosition,
            offset: self.positionAbs,
            item: this.fromOutside ? this.currentItem : self.currentItem,
            sender: inst ? inst.element : null
        };
    }
    

    似乎已经成功了,虽然很讨厌。而且可能不是万无一失的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-03
      • 1970-01-01
      • 2011-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多