Ich habe 2 JavaScript-Funktion, die als Objekteigenschaft verwendet werden. Ich möchte zwei Funktionen gleichzeitig ausführen. Ich habe sie an planogram
Funktion angeschlossen, aber immer noch nicht funktioniert und geben Fehler. Hier ist mein Code.Wie führe ich 2 JavaScript-Funktionen gleichzeitig aus?
function planogram(node, pt, gridpt) {
avoidNodeOverlap(node, pt, gridpt);
stayInGroup(node, pt, gridpt);
}
// a Part.dragComputation function that prevents a Part from being dragged to overlap another Part
function avoidNodeOverlap(node, pt, gridpt) {
// this assumes each node is fully rectangular
var bnds = node.actualBounds;
var locate = node.location;
// see if the area at the proposed location is unoccupied
// use PT instead of GRIDPT if you want to ignore any grid snapping behavior
var x = gridpt.x - (locate.x - bnds.x);
var y = gridpt.y - (locate.y - bnds.y);
var r = new go.Rect(x, y, bnds.width, bnds.height);
// maybe inflate R if you want some space between the node and any other nodes
if (isUnoccupied(r, node)) return pt; // OK
return locate; // give up -- don't allow the node to be moved to the new location
}
function stayInGroup(part, pt, gridpt) {
// don't constrain top-level nodes
var grp = part.containingGroup;
if (grp === null) return pt;
// try to stay within the background Shape of the Group
var back = grp.findObject("rack");
if (back === null) return pt;
// allow dragging a Node out of a Group if the Shift key is down
if (part.diagram.lastInput.shift) return pt;
var p1 = back.getDocumentPoint(go.Spot.TopLeft);
var p2 = back.getDocumentPoint(go.Spot.BottomRight);
var b = part.actualBounds;
var loc = part.location;
// find the padding inside the group's placeholder that is around the member parts
var m = (grp.placeholder !== null ? grp.placeholder.padding : new go.Margin(0));
// now limit the location appropriately
var x = Math.max(p1.x + m.left, Math.min(pt.x, p2.x - m.right - b.width - 1)) + (loc.x-b.x);
var y = Math.max(p1.y + m.top, Math.min(pt.y, p2.y - m.bottom - b.height - 1)) + (loc.y-b.y);
return new go.Point(x, y);
}
Ich habe auch versucht stayInGroup
Funktion innerhalb avoidNodeOverlap
Funktion aufzurufen, aber stayInGroup
Funktion ignoriert. Wenn jemand eine Idee hat zu helfen, schätze ich es sehr. Entschuldigung für meine schlechte Grammatik, danke
@Satpal warum würde es parallel ausführen? – Mahi
@Satpal noch nicht funktioniert –