【问题标题】:Change:position event for every cell in the paper using joint.js更改:使用joint.js为论文中每个单元格的位置事件
【发布时间】:2015-10-18 19:09:00
【问题描述】:

点击论文的空白处会添加一个新单元格:

paper.on({
    'blank:pointerdblclick': function(event, x, y) {
        var rect = new joint.shapes.app.Standard({
            position: { x: x, y: y },
            size: { width: 100, height: 80 },
        });

        graph.addCell(rect);

        rect.on('change:position', function() {
            paper.fitToContent();
        });
    }
});

但是由于change:position 事件是在blank:pointerdblclick 事件中设置的,它只会触发新元素。但应该为本文存在的所有单元格设置它。 因此,为了移动纸上的任何单元格,应该执行 fitToContent() 函数...

我该怎么做?

P.S.:标准元素的定义如下:

joint.shapes.app.Standard = joint.shapes.basic.Generic.extend({
    markup: '<rect/><circle class="port-top"/><circle class="port-bottom"/><circle class="port-right"/><circle class="port-left"/><text/>', 
    defaults: joint.util.deepSupplement({
        type: 'app.Standard',
        attrs: {
            ...
        }
    }, joint.shapes.basic.Generic.prototype.defaults)
});

【问题讨论】:

    标签: javascript jointjs


    【解决方案1】:

    使用graph.getElements() 并遍历它们设置处理程序

    graph.getElements().forEach(function(element) {
        element.on('change:position', function() {
            paper.fitToContent();
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 2019-11-17
      相关资源
      最近更新 更多