TypeError:$ source.offset不是函数

时间:2014-05-27 09:22:35

标签: javascript jquery function jquery-ui-draggable jquery-ui-droppable

我有一个树形结构,可以将元素拖放到另一个元素中。我的目标是当树中的元素或节点被拖放到外部元素时,我希望从树的元素到外部位置绘制一条线。

我将代码分开进行拖放。我试图将代码集成到我的树结构中并得到此错误。我确实看到了类似的错误,但无法准确了解错误究竟是什么。这是给我错误的代码。

end: function(item, hover, placeholder, helper) {
    if (placeholder.parent().length) {
    var tree = $('#tree1').aciTree('api');
    if (tree.isItem(item)) {
        var id = tree.getId(item);
        var label = tree.getLabel(item);
        if (this._instance.jQuery.hasClass('any')) {
            this._instance.jQuery.find('li:not(.aciSortablePlaceholder)').remove();
        }
        var item = $('<li id="item-' + id + '">' + label + '</li>');
        var sourceId = id;
        var destinationId = sourceId;
        drawLine(sourceId, destinationId);
        //This is how the function is called
        placeholder.after(item).detach();
     } 
        else {
            placeholder.detach();
     }
}
helper.detach();
}});

function drawLine(eTarget, eSource) {
    setTimeout(function () {
    var $source = eSource;
    var $target = eTarget;
    var originX = $source.offset().left + $source.width() + 20 + 4;
    // In the $source.offset() I am getting the error.
    var originY = $source.offset().top + (($source.height() + 20 + 4) / 2);

    var endingX = $target.offset().left;
    var endingY = $target.offset().top + (($target.height() + 20 + 4) / 2);

    var space = 20;
    var color = "black";

    var a = "M" + originX + " " + originY + " L" + (originX + space) + " " + originY; // beginning
    var b = "M" + (originX + space) + " " + originY + " L" + (endingX - space) + " " + endingY; // diagonal line
    var c = "M" + (endingX - space) + " " + endingY + " L" + endingX + " " + endingY; // ending
    var all = a + " " + b + " " + c;

    console.log("New Line ----------------------------");
    console.log("originX: " + originX + " | originY: " + originY + " | endingX: " + endingX + " | endingY: " + endingY + " | space: " + space + " | color: " + color );            
    console.log(all); 

    myLines[myLines.length] = svg
    .path(all)
    .attr({
         "stroke": color,
         "stroke-width": 1,
         "stroke-dasharray": "-"
     });
 }, 1000);

PS:我正在使用Firefox。 eTarget和eSource并获取所提供的值。

0 个答案:

没有答案