Javascript jointjs:我想得到source的值";:{";id";:来自json文本

Javascript jointjs:我想得到source的值";:{";id";:来自json文本,javascript,jquery,json,Javascript,Jquery,Json,我想从以下JSON文本中获取“source”:{“id”:中的文本值,其中包含JSON: { "cells": [ { "type": "devs.Model", "size": { "width": 40, "height": 40 }, "inPorts": [""], "outPorts": [""], "position": { "x": 103, "y": 345 }, "angle

我想从以下JSON文本中获取“source”:{“id”:中的文本值,其中包含JSON:

{
    "cells":
    [
        {
            "type": "devs.Model", "size": { "width": 40, "height": 40 },
            "inPorts": [""], "outPorts": [""], "position": { "x": 103, "y": 345 },
            "angle": 0, "id": "4a8edbca-dd9d-4164-bf0a-fc4cbffdca86", "z": 1,
            "attrs": {
                ".label": { "text": "aa", "ref-x": 0.4, "ref-y": 0.2 },
                "rect": { "fill": "#2ECC71" },
                ".inPorts circle": { "fill": "#16A085", "magnet": "active", "type": "input" },
                ".outPorts circle": { "fill": "#E74C3C", "type": "output" },
                ".inPorts>.port0>.port-label": { "text": "" },
                ".inPorts>.port0>.port-body": { "port": { "id": "in8", "type": "in" } },
                ".inPorts>.port0": { "ref": ".body", "ref-y": 0.5 },
                ".outPorts>.port0>.port-label": { "text": "" },
                ".outPorts>.port0>.port-body": {
                    "port": { "id": "out9", "type": "out" }
                },
                ".outPorts>.port0": { "ref": ".body", "ref-y": 0.5, "ref-dx": 0 }
            }
        },
        {
            "type": "link", "source": {}, "target": {}, "id": "35173392-8b69-44fc-b6f4-f7c8a62319bb", "z": 2, "attrs": {}
        },
        {
            "type": "devs.Model", "size": { "width": 40, "height": 40 },
            "inPorts": [""], "outPorts": [""], "position": { "x": 603, "y": 488 },
            "angle": 0, "id": "39e8bc7f-0553-4c5a-b198-b948b0905ae7", "z": 3,
            "attrs": {
                ".label": { "text": "aaa", "ref-x": 0.4, "ref-y": 0.2 },
                "rect": { "fill": "#2ECC71" },
                ".inPorts circle": { "fill": "#16A085", "magnet": "active", "type": "input" },
                ".outPorts circle": { "fill": "#E74C3C", "type": "output" },
                ".inPorts>.port0>.port-label": { "text": "" },
                ".inPorts>.port0>.port-body": { "port": { "id": "in15", "type": "in" } },
                ".inPorts>.port0": { "ref": ".body", "ref-y": 0.5 },
                ".outPorts>.port0>.port-label": { "text": "" },
                ".outPorts>.port0>.port-body": { "port": { "id": "out16", "type": "out" } },
                ".outPorts>.port0": { "ref": ".body", "ref-y": 0.5, "ref-dx": 0 }
            }
        },
        {
            "type": "link", "source": { "id": "4a8edbca-dd9d-4164-bf0a-fc4cbffdca86", "selector": "g:nth-child(1) g:nth-child(4) g:nth-child(1) circle:nth-child(1) ", "port": "out9" },
            "target": { "id": "39e8bc7f-0553-4c5a-b198-b948b0905ae7", "selector": "g:nth-child(1) g:nth-child(3) g:nth-child(1) circle:nth-child(1) ", "port": "in15" },
            "id": "19bfe3a0-bb48-4665-8f2b-807c3bc33451", "embeds": "", "z": 4,
            "attrs": { ".marker-target": { "d": "M 10 0 L 0 5 L 10 10 z" } }
        }]
}
我知道


但它不起作用

您不需要对其进行字符串化然后重新解析。只需访问以下字段:

alert(graph.cells[3].source.id);

.id

(代码>代码>var-obj={”代码>var-obj={{”代码>var-obj的主要是以下几方面,“输入口“,,,,,,,,,,,,,,,,,,位置:,,,,,位置:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,啊,,“.outPorts circle:{”fill:“{”E74C3C”,“type:“output”},.inPorts>.port0>.port label:{”text:“},.inPorts>.port0>.port body:{”port:{”port:{”id:“in8”,“type:“in”},.inPorts>.port0:{”ref:“ref:”.outPorts>.ports>.port0>.port label:{”text:“.outPorts>.ports:{”port body:{”port:“.outPorts:{”id:“in8”,“type:“},.in8”,“type:“.inport0:”,.inPorts:“.inport0:{”port:{”port:{”port:“ref”port:“ref”port:“ref-y:“.outPorts:”.outPorts0.5,“ref-dx”:0.5,“ref-dx”:0.5,“ref-dx”:0.5,“ref-dx”:0.5,”参考参考:参考:0.5,”参考:0.5,“ref-dx”:0.5,“ref-dx”:0.5”,参考:0.5,”参考:参考:0}},,{“源:::::,,,,,目标:,,,,目标:,,id:,id:,id:,,id:,,id:,,id:,,id:,,id:,,id:,,,,id:id:“id:,,,,,id:,,,,,,,,,,,,,,,id:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,aaa,“参考-x”:0.4,“参考-y”“:0.2},,”rect:“{”填充“:”2ECC71“},”.inPorts圆圈“{”填充“:”16A085“,”磁铁“:”活动“,”类型“:”输入“},”.outPorts圆圈“{”填充“:”E74C3C“,”类型“:”输出“,.inPorts>.port0>.port标签“{”文本“},.inPorts>.port0端口体“:{”端口id:”in15“,”类型“:”输入“,”在“},.inPorts>.inPorts>.ref:”端口体“{0:”文本“>.ref:”端口体“{}该国的出口。该国的出口。该国的出口。该国的出口。该国的出口。该国的出口。该国的出口。该国的出口。该国的出口。该国的出口。该国的出口。该国的出口。该国的出口。该国的出口。该国的出口。该国的出口。出口。该国的出口。出口。该国的出口。出口。该国的出口。出口。该国的出口。出口。出口。该国的出口。出口。该国的出口。出口。出口。该国的出口。出口。出口。出口。该国的出口。出口。出口。出口。该国的出口。出口。出口。出口。出口。出口。出口。0。出口。0。出口。0。出口。0。出口。0。出口。0。出口。0。该国的出口。出口。出口。0。0。0。0。0。出口。门门门门门门0。0。0。0。0。0。门门0。门门门门门,“选择器”:“g:N子(1)g:N子(3)g:N子(1)圆:N子(1)”,“端口”:“in15”},“id”:“19bfe3a0-bb48-4665-8f2b-807c3bc33451”,“嵌入”:“z”:4,“属性”:{.marker target”:{“d”:“M 10 0 L 0 5 L 10 z”}};
警报(obj.cells[3].source['id']);尽管我不字符串化,但我无法在另一侧获取值,但我可以在发出警报时获取标签值(obj.cells[0].attrs['.label'].text);
alert(graph.cells[3].source.id);