【发布时间】:2015-10-01 13:26:52
【问题描述】:
我是 JointJS 的新手,我正在尝试关注 tutorial about creating links when dropping elements on top of each other。
当我尝试运行它时,我在 chrome 控制台中收到此错误:
Uncaught ReferenceError: g is not defined
paper.on('cell:pointerup', function(cellView, evt, x, y) {
// Find the first element below that is not a link nor the dragged element itself.
var elementBelow = graph.get('cells').find(function(cell) {
if (cell instanceof joint.dia.Link) return false; // Not interested in links.
if (cell.id === cellView.model.id) return false; // The same element as the dropped one.
if (cell.getBBox().containsPoint(g.point(x, y))) {
return true;
}
return false;
});
// If the two elements are connected already, don't
// connect them again (this is application specific though).
if (elementBelow && !_.contains(graph.getNeighbors(elementBelow), cellView.model)) {
graph.addCell(new joint.dia.Link({
source: { id: cellView.model.id }, target: { id: elementBelow.id },
attrs: { '.marker-source': { d: 'M 10 0 L 0 5 L 10 10 z' } }
}));
// Move the element a bit to the side.
cellView.model.translate(200, 0);
}
});
我看到 g 从未在上面的代码中创建,它也没有在教程中创建,它指的是什么?
【问题讨论】:
标签: javascript geometry jointjs referenceerror