1

我手中有以下 JSON 数据,我需要创建一个表,但数据是动态的(行标题和列标题和单元格值)。

JSON结构如下,

{        
    "data": {
        "vertical_header": [
            "football",
            "hockey"
        ],
        "horizontal_header": [
            "China",
            "Brazil",
            "Australia"
        ],
        "researchDetails": [
            {
                "country": "brazil",
                "game": "hockey",
                "player": "Mr.r"
            },
            {
                "country": "china",
                "game": "hockey",
                "player": "Mr.X"
            },
            {
                "country": "china",
                "game": "football",
                "player": "Mr.Y"
            },
            {
                "country": "china",
                "game": "football",
                "player": "Mr.Z"
            },
            {
                "country": "brazil",
                "game": "football",
                "player": "Mr.M"
            },
            {
                "country": "brazil",
                "game": "football",
                "player": "Mr.E"
            }    
        ]
    }
}

以下是表结构,我必须解析这样的 JSON 以使用车把模板构造一个像这样的动态表。标题也是动态的,我必须创建一个数组(2D/3D),以便可以构造以下内容,

<html>
</body>
<table border="1">
        <tr><th/><th>hockey</th><th>football</th></tr>
        <tr><td rowspan="2">china</td><td>Mr.X</td><td>Mr.Y</td></tr>
        <tr><td></td><td>Mr.Z</td></tr>
        <tr><td rowspan="2">brazil</td><td>Mr.r</td><td>Mr.M</td></tr>
        <tr><td ></td><td>Mr.e</td></tr>
        <tr><td>Australia</td><td></td><td/></tr>
    </table>
</body>
</html
4

0 回答 0