javascript - How do I add references to HTML elements in to my JSON? -


the cytoscape.js example shown here has reference in json:

 container: document.getelementbyid('cy'), 

eg.

cytoscape({    container: document.getelementbyid('cy'),    elements: [     { // node n1       //... snip     }] }); 

if manually create json string, , call cytoscape() on it, works fine.

however, i've returning json string servlet, , on client side, need add container value.

i've tried:

function updategraph(json) {     console.log(json);      pjson = json.parse(json);     pjson["container"] =  document.getelementbyid('graph-container');     json = json.stringify(pjson);     console.log(json);      cytoscape(json); } 

but show container element as:

"container":{} 

what's correct way add html element reference?

document.getelementbyid('graph-container'); 

will return html element embedded within <>. javascript object notation(json) cannot hold such elements, cannot parse such elements. can hold arrays, objects of string, boolean, numbers , null.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -