gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:47:50 26 4
gpt4 key购买 nike

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

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com