jointjs:我想从json文本中获取label的值

时间:2015-05-20 13:52:13

标签: javascript jquery json

我想获得文本的值a"标签"以及来自此JSon文本的带有JSON的类型:

{
    "cells": [{
        "type": "devs.Model",
        "size": {
            "width": 40,
            "height": 40
        },
        "inPorts": [""],
        "outPorts": [""],
        "position": {
            "x": 168,
            "y": 99
        },
        "angle": 0,
        "id": "c7cf7b2d-3b54-4dd1-9cbf-7a37a72559fc",
        "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": "1e977b11-c003-4c22-ba48-c04994f63c79",
        "z": 2,
        "attrs": {}
    }]
}

对于标签,我这样做:document.write(jsonString.cells[0].attrs.label.text);

,类型为:(jsonString.cells[0].attrs.label.text);

var jsonString = JSON.stringify(graph);
document.write(jsonString.cells[0].type);

0 个答案:

没有答案