簡體   English   中英

動態添加的端口無法在jointjs中克隆?

[英]dynamically added ports can't be cloned in jointjs?

單擊按鈕時,我向元素添加了端口。

這是我的代碼

joint.shapes.devs.Jointpoint = {}; 
joint.shapes.devs.Jointpoint = joint.shapes.devs.Model
.extend({
    markup : '<g class="rotatable"><g class="scalable"><ellipse class="bianyaqiOO" ry="30" rx="30" id="svg_1" cy="30" cx="30" stroke-width="1.5" stroke="#222" fill="none"/></g></g>',
    //portMarkup: '<g class="port port<%= id %>"><rect class="port-body"/><text class="port-label"/></g>',
    defaults : joint.util.deepSupplement({
        type : 'devs.Jointpoint',

        ports : {
            groups : {
                'in' : {
                    position : {
                        name : 'top'
                    },
                    attrs : {
                        '.port-label' : {
                            fill : '#000'
                        },
                        '.port-body' : {
                            'fill-opacity' : 0.5,
                            'stroke-opacity' : 0.5,
                            r : 2,
                            magnet : true
                        }
                    },
                    label : {
                        position : {
                            name : 'top',
                            args : {
                                y : -10
                            }
                        }
                    }
                },
            }
        }
    }, joint.shapes.devs.Model.prototype.defaults)
});

joint.shapes.devs.BianyaqiOOView = joint.shapes.devs.ModelView;

var Jointpointicon = new joint.shapes.devs.Jointpoint({
position : {
x : 500,
y : 16
},
size : {
width : 20,
height : 20
},
isInteractive : false,
});
Jointpointicon.addTo(graph);
var selected;
paper.on('cell:pointerup', function (cellView) {
                selected = cellView.model
           if(cellView.model.get('name') == 'addPort'){
                selected.addPort({group:'in');
       });

paper.on('blank:pointerup', function (evt, x, y) {
                graph.addCell(selected.clone());
       });

當我點擊addport按鈕時,我可以為所選元素添加一個端口,但是當我點擊紙上的空白區域時,我克隆了所選元素,但沒有端口,我不確定發生了什么,但是如果我改變它像這樣 :

var Jointpointicon = new joint.shapes.devs.Jointpoint({
position : {
x : 500,
y : 16
},
size : {
width : 20,
height : 20
},
isInteractive : false,
inPorts : [ 'in' ],
});

加載后會有一個'in'端口,它可以被克隆,但是如果我通過單擊addPort按鈕添加一些新端口,所有添加的端口都不會被克隆,我做錯了什么嗎?

最后我弄清楚問題是什么。 我使用 addInPort(portname) 和 addOutPort(portname) 而不是 addPort()。 它工作得很好。

似乎 addPort() 無法將端口添加到“輸入”或“輸出”,它可能會將端口添加到新數組。 因此,當克隆具有添加端口的新單元格時,它只會克隆 'in' 和 'out' 數組中的端口,新添加的端口被添加到無名稱數組中,因此它可能不會被克隆。 無論如何使用 addInPort(portname) 和 addOutPort(portname) 是好方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM