简体   繁体   English

结合使用jsPlumb和动态内容

[英]Using jsPlumb with dynamic content

ill try to user jsPlumb:Flowchart within MySQL based dynamic content. 请尝试在基于MySQL的动态内容中使用jsPlumb:Flowchart。

My Code is based on the Demo example for Flowchart:jQuery 我的代码基于Flowchart:jQuery的演示示例
im generating my Endpoints within my Database query 我在数据库查询中生成我的端点

$plumb .= '_addEndpoints("drag'.$id_kurs.'", ["TopCenter", "BottomCenter", "LeftMiddle", "RightMiddle"]);

and im adding it to my content at the end of the Database content 并在数据库内容的末尾将其添加到我的内容中

$vorschau .= '      </div>
                    </DIV>

                    <script>
                            jsPlumb.ready(function() {
                                    var instance = jsPlumb.getInstance({
                                        DragOptions : { cursor: "pointer", zIndex:2000 },

                                        ConnectionOverlays : [
                                            [ "Arrow", { location:1 } ],
                                            [ "Label", { 
                                                location:0.5,
                                                id:"label",
                                                cssClass:"aLabel"
                                            }]
                                        ],
                                    });

                                    var connectorPaintStyle = {
                                        lineWidth:2,
                                        strokeStyle:"#db0018",
                                        joinstyle:"round",
                                        outlineColor:"white",
                                        outlineWidth:1
                                    },
                                    // .. and this is the hover style. 
                                    connectorHoverStyle = {
                                        lineWidth:2,
                                        strokeStyle:"#000000",
                                        outlineWidth:1,
                                        outlineColor:"white"
                                    },
                                    endpointHoverStyle = {
                                        fillStyle:"#000000",
                                        strokeStyle:"#db0019"
                                    },
                                    sourceEndpoint = {
                                        endpoint:["Rectangle",{ width:18, height:18}],
                                        paintStyle:{ 
                                            fillStyle:"#db0013"
                                        },
                                        maxConnections:999,     
                                        isSource:true,
                                        isTarget:true,
                                        connector:[ "Flowchart", { stub:[40, 60], gap:10, cornerRadius:5, alwaysRespectStubs:true } ],                                              
                                        connectorStyle:connectorPaintStyle,
                                        hoverPaintStyle:endpointHoverStyle,
                                        connectorHoverStyle:connectorHoverStyle,
                                        dragOptions:{}        
                                    },      
                                    init = function(connection) {           
                                        connection.getOverlay("label").setLabel(connection.sourceId.substring(15) + "-" + connection.targetId.substring(15));
                                        connection.bind("editCompleted", function(o) {
                                            if (typeof console != "undefined")
                                                console.log("connection edited. path is now ", o.path);
                                        });
                                    };          

                                    var _addEndpoints = function(toId, sourceAnchors, targetAnchors) {
                                            for (var i = 0; i < sourceAnchors.length; i++) {
                                                var sourceUUID = toId + sourceAnchors[i];
                                                instance.addEndpoint("flowchart" + toId, sourceEndpoint, { anchor:sourceAnchors[i], uuid:sourceUUID });                     
                                            }
                                    };                                                      

                                    instance.doWhileSuspended(function() {


                                        '.$plumb.'

                                        instance.bind("connection", function(connInfo, originalEvent) { 
                                            init(connInfo.connection);
                                        });         

                                        instance.bind("click", function(conn, originalEvent) {
                                            if (confirm("Delete connection from " + conn.sourceId + " to " + conn.targetId + "?"))
                                                jsPlumb.detach(conn); 
                                        }); 

                                        instance.bind("connectionDrag", function(connection) {
                                            console.log("connection " + connection.id + " is being dragged. suspendedElement is ", connection.suspendedElement, " of type ", connection.suspendedElementType);
                                        });     

                                        instance.bind("connectionDragStop", function(connection) {
                                            console.log("connection " + connection.id + " was dragged");
                                        });

                                        instance.bind("connectionMoved", function(params) {
                                            console.log("connection " + params.connection.id + " was moved");
                                        });
                                    });
                            });
                    </script>';

all of that is within an function 所有这些都在一个函数内

The HTML/CSS structure is showing correctly but it wont show my endpoints. HTML / CSS结构显示正确,但不会显示端点。
I have included all needed js/css files, as i said im using the DEMO as basement for my code. 我已经包含了所有需要的js / css文件,正如我所说的那样,我使用DEMO作为代码的基础。

My error message: 我的错误讯息:

TypeError: el is null TypeError:el为空
...fsetTop, op = (relativeToRoot || (container != null && el.offsetParent != conta... ... fsetTop,op =(relativeToRoot ||(容器!=空&& el.offsetParent!=污染...

The Line within dom-adapter the error is relating to: dom-adapter中的行错误与以下内容有关:

var l = el.offsetLeft, t = el.offsetTop, op = (relativeToRoot || (container != null && el.offsetParent != container)) ? var l = el.offsetLeft,t = el.offsetTop,op =(relativeToRoot ||(container!= null && el.offsetParent!= container))吗? el.offsetParent : null; el.offsetParent:null;

The code in question contains only function & variable definitions, no executions which actually create endpoints/connections. 所讨论的代码仅包含函数和变量定义,而没有实际创建端点/连接的执行。

As is visible in the source code of jsPlumb demo : https://jsplumbtoolkit.com/demo/home/demo.js 在jsPlumb演示的源代码中可见: https ://jsplumbtoolkit.com/demo/home/demo.js

The connect calls are missing. 连接呼叫丢失。

var connection1 = instance.connect({
        source:"window1", 
        target:"window2",               
        connector:["Bezier", { curviness:70 }],
        cssClass:"c1",
        endpoint:"Blank",
        endpointClass:"c1Endpoint",                                                    
...});

These calls are missing, which are used in the demo to create connections & render corresponding endpoints. 这些调用丢失了,这些调用在演示中用于创建连接和渲染相应的端点。

Found my mistake: 发现我的错误:

$plumb .= '_addEndpoints("drag'.$id_kurs.'"...

Defined my Endpoints like that 这样定义我的端点

the objects had the same id 这些对象具有相同的ID

<div class="dragable" id="drag'.$id_kurs.'">

but is has to be: 但必须是:

<div class="dragable" id="flowchartdrag'.$id_kurs.'">   

It was just luck to find it, cause i didnt espect the mistake at this part 找到它只是运气,因为我没有想到这部分的错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM