javascript – 在joint.js中读取JSON?

前端之家收集整理的这篇文章主要介绍了javascript – 在joint.js中读取JSON?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我想让joint.js库读取我的JSON并将其显示为图表…

var paper = new joint.dia.Paper({
    el: $('#paper'),width: 600,height: 200,model: graph
});

var graph = new joint.dia.Graph;

jsonstring = '{"employees": [ { "firstName":"John","lastName":"Doe" },{ "firstName":"Anna","lastName":"Smith" },{ "firstName":"Peter","lastName":"Jones" } ] }';

graph.fromJSON(JSON.parse(jsonstring));
最佳答案
来自joint.dia.Graph的API:

joint.dia.Graph is the model holding all the cells (elements and
links) of the diagram. It’s a 07001. The collection of all the cells
is stored in the property cells.

所以预期的JSON应该采用以下形式:{cells:[]}.其中,单元格是元素和链接的数组.每个元素都应该具有以下形式:

{ 
    id: 

参考:Using Server Data with JointJS

原文链接:https://www.f2er.com/js/429845.html

猜你在找的JavaScript相关文章