我正在进行嵌套函数调用,但同时我需要将变量传递给嵌套函数,我可以这样做。这就是我想要做的事情
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,
它工作正常,但我真的需要包含它。有没有办法做到这一点??
非常感谢您的帮助!
答案 0 :(得分:3)
将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",
} ]
]
};
}