【问题标题】:dynamically adding a port to a jointjs element动态地将端口添加到jointjs元素
【发布时间】:2016-02-09 21:49:06
【问题描述】:

所以,我晚上大部分时间都在与这个作斗争,我承认失败。我在这个论坛上问这个问题,知道有人会说“看这里”,这可以节省我几个小时:)

认为我可以在joint.shapes.devs.Model.extend中添加一个函数(就像这样:

addPort:函数(名称){ var portsArray = this.attributes.outPorts; portsArray.push(name); }

但显然不是

我已经搜索了演示和源代码,但无济于事

所以,问题::

如何向现有元素添加新端口?

我也在jointjs google groups上问过这个问题,但是那里的流量太少了,我希望是那个地方;)

谢谢

【问题讨论】:

    标签: svg jointjs


    【解决方案1】:

    请使用set 更新属性,而不是直接修改它们。 这很重要,因为模型可以触发事件而视图可以处理它(渲染端口)。

    addPort: function(port) {
         // It is also important to clone the array here
         // as we do not want do modify the original attribute value.
         // Setting the same value on the model would trigger no event.
         /*
           var m = new Backbone.Model({ b: [] });
           var array = m.get('b');
           array.push('d');
           m.set('b', array); // -> no event triggered, m.get('b') === array
         */
         var ports = (this.get('outPorts') || []).slice();
         ports.push(port);
         this.set('outPorts', ports);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 2014-08-03
      • 2016-01-01
      相关资源
      最近更新 更多