0
是否有可能有多個cytoscape圖形實例是不相關的,但共享相同的源元素?多個不相關的圖形實例具有相同的源元素?
這裏是我想要做的一個例子:https://jsfiddle.net/fa8hbdnh/
var elements = [
{ data: { id: 'n1'}, position: {x:100, y: 100}},
{ data: { id: 'n2'}, position: {x:150, y :150}},
//--->Edges--->
{ data: {id: 'e1', source: 'n1', target: 'n2'}},
];
var graph1 = cytoscape({
headless: true,
elements: elements
});
var graph2 = cytoscape({
headless: true,
elements: elements
});
graph1.elements()[0].data('foo',100); // Only changing graph1...
console.log(graph2.elements()[0].data('foo')); // ...however graph2 is also modified
(這需要Cytoscape的庫 - http://js.cytoscape.org/)
正如你所看到的,我改變graph1但圖2是也受到影響。有沒有辦法在一個實例上保存數據元素而不影響其他實例?