【问题标题】:ReferenceError: g is not definedReferenceError: g 未定义
【发布时间】: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


    【解决方案1】:

    g (Geometry documentation) 允许调用几个不同的函数来返回特定对象或对点、线和形状进行操作。示例:

    g.point(3,4) // -> {x: 3, y: 4}
    

    如果未定义g,则意味着您正在使用的其中一个JS文件要么在开头缺少g声明(var g = window.g || {};),要么在JointJS声明之前尝试使用它/快速。

    【讨论】:

      猜你喜欢
      • 2014-08-20
      • 1970-01-01
      • 2012-08-24
      • 2015-10-04
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多