H5W3
当前位置:H5W3 > 其他技术问题 > 正文

【Web前端问题】web对象数组,取值问题

大佬们,请问如何嵌套
如果为取eventAtt.Protection的值,则SnapPolygon.color.r=0,id的值为Sectionnumber,point的值为area,tips的值为#Sectionnumber#。
如果为eventAtt.Removalarea,则SnapPolygon.color.r=255,id的值为Sectionnumber,point的值为area,tips的值为#Sectionnumber#

取值的对象代码

var eventAtt={
        "Protection": [
            {
                "area": [
                    [
                        0.2,
                        0.2
                    ],
                    [
                        0.5,
                        0.2
                    ],
                    [
                        0.5,
                        0.5
                    ],
                    [
                        0.2,
                        0.5
                    ]
                ],
                "Sectionnumber": 1
            },
            {
                "area": [
                    [
                        0.2,
                        0.2
                    ],
                    [
                        0.5,
                        0.2
                    ],
                    [
                        0.5,
                        0.5
                    ],
                    [
                        0.2,
                        0.5
                    ]
                ],
                "Sectionnumber": 3
            }
        ],
        "Removalarea": [
            {
                "area": [
                    [
                        0.2,
                        0.2
                    ],
                    [
                        0.5,
                        0.2
                    ],
                    [
                        0.5,
                        0.5
                    ],
                    [
                        0.2,
                        0.5
                    ]
                ],
                "Sectionnumber": 2
            },
            {
                "area": [
                    [
                        0.2,
                        0.2
                    ],
                    [
                        0.5,
                        0.2
                    ],
                    [
                        0.5,
                        0.5
                    ],
                    [
                        0.2,
                        0.5
                    ]
                ],
                "Sectionnumber": 4
            }
        ]
    };

需要实例的代码

var json ={"SnapPolygonList":{"SnapPolygon":[{"id":"1","polygonType":"1","color":{"r":"0","g":"255","b":"0"},"tips":"#1#","isClosed":"true","pointList":{"point":[{"x":"0.324415","y":"0.496516"},{"x":"0.538462","y":"0.486063"},{"x":"0.438127","y":"0.806620"},{"x":"0.269231","y":"0.759582"}]}},{"id":"2","polygonType":"1","color":{"r":"255","g":"0","b":"0"},"tips":"#2#","isClosed":"true","pointList":{"point":[{"x":"0.168896","y":"0.728223"},{"x":"0.650502","y":"0.780488"},{"x":"0.493311","y":"0.945993"},{"x":"0.143813","y":"0.970383"},{"x":"0.157191","y":"0.949477"}]}}]}};

存值的代码

var jsonlist= {
            "SnapPolygonList":{
                "SnapPolygon":[
                    {
                        "id":Sectionnumber,
                        "polygonType":"1",
                        "color":{
                            "r":"0",
                            "g":"255",
                            "b":"0"
                        },
                        "tips":"#Sectionnumber#",
                        "isClosed":"true",
                        "pointList":{
                            "point":[
                                area
                            ]
                        }
                    },
                    {
                        "id":Sectionnumber,
                        "polygonType":"1",
                        "color":{
                            "r":"255",
                            "g":"0",
                            "b":"0"
                        },
                        "tips":"#区域编号#",
                        "isClosed":"true",
                        "pointList":{
                            "point":[
                                area
                            ]
                        }
                    }
                ]
            }
        };

回答:

循环判断下分别处理下不就好了?

本文地址:H5W3 » 【Web前端问题】web对象数组,取值问题

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址