【问题标题】:Remove link by ID from JointJS graph?从 JointJS 图中按 ID 删除链接?
【发布时间】:2017-02-18 10:28:20
【问题描述】:

JointJS 提供了从图中删除链接的方法,例如 dia.Link.prototype.disconnectdia.Link.prototype.remove

但是,它们首先取决于对链接对象的访问权限。有什么方法可以通过 ID 查询 JointJS 图(joint.dia.Graph)的链接对象?

我可以手动维护一个从 ID 到链接对象的 JS 映射,但这听起来很乏味。

【问题讨论】:

    标签: javascript jointjs


    【解决方案1】:

    graph.getCell(linkId) 没有做你想做的事吗?

    例如

    graph.removeCells(graph.getCell(linkId))
    

    【讨论】:

    • removeCells 接受一个数组,应该是graph.removeCells([graph.getCell(linkId)])graph.getCell(linkId).remove()
    【解决方案2】:

    如果你想访问任何链接,你有两个选择,然后你可以删除它们

    _.each(cellView.paper.model.getLinks(), function(link) {
            console.log(link.id, link.get('source'), link.get('target'))
         })
    
    OR
    
    _.each(cellView.paper.model.get('cells'), function(cell) {
        if (cell instanceof joint.dia.Link) {
           // cell is a link
            console.log(cell.id, cell.get('source'), cell.get('target'))
        } else {
            // cell is an element
            console.log(cell.id, cell.get('position'), cell.get('size'), cell.get('angle'))
       }
    })
    

    由大卫·德尔曼本人提供 https://groups.google.com/forum/#!topic/jointjs/cWJAK9gSC-Q

    在图表上你可以发出一个事件

    graph.on('change:source change:target', function(link) {
    you can use link.remove()
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-02
      • 1970-01-01
      • 2014-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多