拖动;放弃克隆

时间:2011-08-02 21:27:01

标签: jquery drag-and-drop draggable jquery-ui-sortable

我正在使用带有Sortable的jquery Draggables。我有一个左边的元素列表,我需要拖放到右边的不同div。可以将左边的相同项目放到多个框中,所以我使用了帮助:“克隆”。一切正常,直到我需要获取对接收事件中克隆的新元素的引用,以便我可以添加一个单击处理程序。

我需要对新元素的引用!

<div>
        <div style="float: left; width: 300px;">
            <div id="FieldList">
                <h2>Loading</h2>            
            </div>
            <input type="button" name="cmdTest" id="cmdTest" value="Test" />
    </div>
    <div style="float: right; width: 300px;">
        <div>
            <div>Select Columns</div>
            <div class="Toolbar"></div>
            <div id="SelectFields" class="DroppableField">

            </div>
        </div>
        <div>
            <div>Conditions</div>
            <div class="Toolbar"></div>
            <div class="DroppableField" style="background-color: Gray; height: 200px;">

            </div>
        </div>
        <div>
            <div>Order</div>
            <div class="Toolbar"></div>
            <div class="DroppableField" style="background-color: Gray; height: 200px;">

            </div>
        </div>
    </div>
    <div style="clear: both;">
    </div>
</div>

使用Javascript:

$(document).ready(function () {

        $(".DroppableField").sortable({
            revert: true,
            receive: function (ui, event) { 
                // ui.helper always seems to be null. Many of the other properties seem to reference the original item.  I need the NEW ONE!!!                  
                $(ui.helper).dblclick(function () {

                });
            }
        });

        $.ajax({
            url: "/condition/getconditions",
            data: {},
            dateType: "json",
            type: "POST",
            success: function (data, successcode, jqXHR) {
                var html = "";
                for (var i = 0; i < data.length; i++) {
                    $("#FieldList").append("<div>" + data[i].Description + "</div>").find("div:last").data("fielddata", data[i]);
                    //html += ;
                }

                $("#FieldList div").draggable({
                    connectToSortable: ".DroppableField",
                    helper: "clone",
                    revert: "invalid"
                });
            }
        });

    });

1 个答案:

答案 0 :(得分:1)

您好像已经反转了回调函数接收的两个参数。

receive: function (ui, event) { 

}

应该是

receive: function (event, ui) { 

}

根据jQuery UI Docs

  

所有回调都会收到两个参数:原始浏览器事件和a   准备了ui对象[...]