可以在全局配置 interacting
定制节点和边的交互行为
graph = new X6.Graph({
container : this.container,
width : 800,
height : 900,
interacting: function (cellView) {
if (cellView.cell.getData() != undefined && !cellView.cell.getData().disableMove) {
return { nodeMovable: false }
}
return true
},
});
然后在子节点的数据中,加入disableMove属性,父节点不加入该属性。
graph.createNode({
id : 'aaa',
x : 0,
y : 0,
width: 100,
height: 100,
data: {
disableMove: false,
},
})
这样在动态绘制节点时,会根据是否有disableMove属性,决定每一个节点是否可拖动。仅给子节点加入disableMove属性,父节点没有disableMove属性,即可实现父节点可拖动,子节点不可拖动的效果。