0

我正在做一个嵌套函数调用,但同时我需要将变量传递给嵌套函数,我可以这样做吗?这就是我想要做的

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,

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

非常感谢您的帮助!

4

1 回答 1

3

将 sourceEndPoint 构造更改为函数并将 JSON 对象作为返回值返回。IE:

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",
                } ]
            ]
        };
    }
于 2012-10-29T23:25:27.387 回答