繁体   English   中英

如何从嵌套函数调用中传递变量

[英]how to pass the variable from the nested function call

我正在执行嵌套函数调用,但同时我需要将变量传递给嵌套函数,我可以这样做吗。 这是我正在尝试这样做的

allSourceEndpoints.push(jsPlumb.addEndpoint(toId, sourceEndpoint(index), { anchor:sourceAnchors[i], uuid:sourceUUID }));


sourceEndpoint(index) = {
            endpoint:"Dot",

            paintStyle:{ fillStyle:"#225588",radius:3 },
            isSource:true,
            isTarget:true,
            maxConnections:-1,
        //  connector:[ "Flowchart", { stub:[40, 60], gap:10 } ],
        //  connector:[ "Flowchart"],

            hoverPaintStyle:connectorHoverStyle,
            connectorHoverStyle:connectorHoverStyle,
            dragOptions:{},
            overlays:[
                [ "Label", { 
                    location:[0.5, 1.5], 
                    label:""+startEnd[index].start,
                    cssClass:"endpointSourceLabel",
                } ]
            ]
        }

上面的代码由于

       index 

通过我在做什么。 我需要那个,因为我需要找出起点。 如果我删除该索引引用和行

         label:""+startEnd[index].start,

它工作正常,但我真的需要包括它。 有没有办法做到这一点??

非常感谢您的帮助!

将sourceEndPoint构造更改为一个函数,并返回JSON对象作为返回值。 即:

sourceEndpoint = function(index) {

    return {
            endpoint:"Dot",

            paintStyle:{ fillStyle:"#225588",radius:3 },
            isSource:true,
            isTarget:true,
            maxConnections:-1,
        //  connector:[ "Flowchart", { stub:[40, 60], gap:10 } ],
        //  connector:[ "Flowchart"],

            hoverPaintStyle:connectorHoverStyle,
            connectorHoverStyle:connectorHoverStyle,
            dragOptions:{},
            overlays:[
                [ "Label", { 
                    location:[0.5, 1.5], 
                    label:""+startEnd[index].start,
                    cssClass:"endpointSourceLabel",
                } ]
            ]
        };
    }

暂无
暂无

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

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