ReferenceError: g не определен

Я новичок в JointJS и пытаюсь следовать этому руководству по созданию ссылок при перетаскивании элементов на друг над другом.

Когда я пытаюсь запустить его, я получаю эту ошибку в консоли Chrome:

Uncaught 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 никогда не создается в приведенном выше коде и не создается в учебнике, на что он ссылается?


person nerfdoit    schedule 01.10.2015    source источник


Ответы (1)


g (документация по геометрии) позволяет вызывать несколько различных функции для возврата определенных объектов или для работы с точками, линиями и формами. Пример:

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

Если g не определено, это означает, что в одном из JS-файлов, которые вы используете, либо отсутствует объявление g в начале (var g = window.g || {};), либо он пытается использовать его до того, как он будет объявлен JointJS/Rappid.

person CPHPython    schedule 24.01.2018