cy.load() elements are lost

独自空忆成欢 提交于 2019-12-11 13:08:40

问题


I'm trying to store the current graph in browser on the server side and now I'm testing how to. I ran into a strange Problem: after jsoning, decycling, stringifying and reloading the graph, the elements are somehow lost.

var j = network_tab.cy.json();
j = JSON.decycle(j);
j = JSON.stringify(j);
network_tab.cy.load(j);

Before decycling the graph, I cannot stringify it. If you look in the stringified version, you can see, that the elements are still there, but after loading, they are gone.

Maybe I have a problem in general with the cy.load() function, but I do hope you guys can help me.

EDIT: The problem seems to be with the stringify function. Then my question boils down how to make the whole object readable for load().

 An element must be of type `nodes` or `edges`; you specified `undefined`   
 console.error( msg );
 cytoscape.js (line 244)
 TypeError: obj._private is undefined

I want to copy the whole thing, but especially the elements, the positions. So is it better to reinitialize the graph completely and when so, how do I add the positions of the nodes?


回答1:


(1) cy.json() is undocumented (and probably not ready for use) until 2.1

(2) You shouldn't need to use JSON.decycle() unless your own data that you're putting in elements have references to one another -- not a good idea in general.

(3) cy.json() gives you the whole graph state as used in intialisation -- not for cy.load(). You could pass json.elements to cy.load() but not the root object, json.

(4) You can alternatively get each individual element as JSON via (the tested and documented prior to 2.1) ele.json() and build your own object to pass to cy.load().

(5) Have you inspected the object you're passing to cy.load()? Can you post it here? You're not passing a JSON string to cy.load(), are you?



来源:https://stackoverflow.com/questions/21113119/cy-load-elements-are-lost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!