我正在执行嵌套函数调用,但同时我需要将变量传递给嵌套函数,我可以这样做吗?这就是我正在尝试做的事情
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",
} ]
]
};
}
关于javascript - 如何从嵌套函数调用中传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13131088/