我是JointJS的新手,我正在尝试遵循此tutorial about creating links when dropping elements on top of each other

当我尝试运行它时,我在chrome控制台中收到此错误:


  未捕获的ReferenceError:未定义g


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从未在上面的代码中创建,并且在本教程中也没有创建,它指的是什么?

最佳答案

gGeometry documentation)允许调用多个不同的函数以返回特定对象或对点,线和形状进行操作。例:

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


如果未定义g,则意味着您正在使用的JS文件之一在开头(g)丢失了它的var g = window.g || {};声明,或者在由JointJS / Rappid声明之前试图使用它。

关于javascript - ReferenceError:未定义g,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32888821/

10-11 12:23