cy.load()元素丢失 [英] cy.load() elements are lost

查看:70
本文介绍了cy.load()元素丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将当前图形存储在服务器端的浏览器中,现在我正在测试操作方法。我遇到了一个奇怪的问题:在对图进行json,循环,字符串化和重新加载后,元素以某种方式丢失了。

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.

也许我总体上有问题cy.load()函数,但我希望你们能对我有所帮助。

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

编辑:问题似乎出在stringify函数上。然后我的问题归结为如何使整个对象对load()可读。

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)直到2.1之前cy.json()才被记录(可能不准备使用)

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

(2)您不需要使用 JSON.decycle()除非要放入元素中的自己的数据相互引用,否则通常不是一个好主意。

(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()提供了初始化时使用的整个图形状态-不适用于 cy.load()。您可以将 json.elements 传递给 cy.load(),但不能传递根对象 json

(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)您也可以通过(在2.1之前进行测试和记录) ele.json()并构建您自己的对象以传递给 cy.load()

(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)您是否检查了要传递给 cy.load()的对象?你可以在这里张贴吗?您没有将JSON字符串传递给 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?

这篇关于cy.load()元素丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆