jsPlumb - 无法将源连接到目标

时间:2016-01-28 18:15:54

标签: connection jsplumb

这是在页面加载时执行的代码:

$(document).ready(function() {
        jsPlumb.importDefaults({
            Connector: ["Bezier", { curviness: 3 }],
            PaintStyle: { strokeStyle: "#4682B4", lineWidth: 4 },
            EndpointStyle: { radius: 10, fillStyle: "#4682B4" },                
            Anchors: ["BottomCenter"]
        });
        jsPlumb.setContainer($("#graph"));

        connections.forEach(function(element) {
            jsPlumb.connect({source: element.source, target: element.target});
        });
    });

在我尝试上面最后一行的连接之前,我在代码中创建了div:

function createDiv(id, innerHTML, width, height, left, top, cssclass) {
        var div = $("<div/>");

        if (cssclass)
            $(div).text(innerHTML);
        else
            $(div).append(innerHTML);

        $("#graph").append(
            $(div)
                .attr("id", id)
                .addClass(cssclass)
                .css({top: top, left: left, cursor: "move"})                    
                .width(width ? width : 180)
                .height(height ? height : 25)
        );

        jsPlumb.draggable($("#" + id));
    }

我一直遇到的错误是“未捕获的TypeError:无法读取属性'添加'未定义”在我尝试连接的行上。我错过了什么?

这是我的HTML:

<!DOCTYPE html>
<html>
<head>  
<script src="scripts/jquery-2.1.4.min.js"></script>    
<script src="scripts/jquery-ui-1.11.4.min.js"></script>
<script src="scripts/jsPlumb-2.0.6-min.js"></script>
<script type="text/javascript">....</script>
</head>
<body>
    <div id="expression"></div> 
    <div id="graph"></div>
</body>
</html>

0 个答案:

没有答案