gpt4 book ai didi

javascript - 在 joint.js 中读取 JSON?

转载 作者:搜寻专家 更新时间:2023-11-01 04:17:55 24 4
gpt4 key购买 nike

我希望 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 Backbone model. The collection of all the cells is stored in the property cells.

所以预期的 JSON 应该是这种形式:{ cells: [] }。其中 cells 是元素和链接的数组。每个元素应具有以下形式:

{ 
id: <string>,
type: '<type of shape>',
attrs: { <attrs> },
position: { x: <int>, y: <int> },
angle: <deg>,
size: { width: <int>, height: <int> },
z: <int>,
... and some other, maybe custom, data properties
}

引用:Using Server Data with JointJS

关于javascript - 在 joint.js 中读取 JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20096360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com