私は2つのjavascript関数をオブジェクトプロパティとして使用します。私は2つの機能を同時に実行したい。私はそれらをplanogram
の機能に参加させましたが、まだ機能しておらず、エラーを出しています。ここに私のコードです。2つのJavaScript関数を同時に実行するには?
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);
}
私もavoidNodeOverlap
関数内stayInGroup
関数を呼び出すしようとしましたが、stayInGroup
機能は無視すること。もし私が本当にそれを感謝するのを助けるアイデアがあれば。私の悪い文法のおかげで申し訳ありません
@Satpalそれはなぜ並列を実行するのでしょうか? – Mahi
@Satpalはまだ働いていません –