首页 > 解决方案 > jexcel从带有空单元格的ajax加载数据

问题描述

<html>
<script src="https://bossanova.uk/jexcel/v3/jexcel.js"></script>
<link rel="stylesheet" href="https://bossanova.uk/jexcel/v3/jexcel.css" type="text/css" />
<script src="https://bossanova.uk/jsuites/v2/jsuites.js"></script>
<link rel="stylesheet" href="https://bossanova.uk/jsuites/v2/jsuites.css" type="text/css" />

<div id="spreadsheet2"></div>

<script>
jexcel(document.getElementById('spreadsheet2'), {
    jexcel(document.getElementById('spreadsheet2'), {
        url:'/v3/test.json',
        columns: [
            { type:'text', width:300 },
            { type:'text', width:100 },
         ]
    });
});
</script>
</html>

我的外部 JSON 响应如下;

{
    "0": {
        "0": "Trawex",            // This should mapped on row=0, col=0
        "1": "Restel",            // This should mapped on row=0, col=1
                                 // now here col 2 and 3 should be filled empty itself.
        "4": "Restel"            // This should mapped on row=0, col=4
    },
    "1": {
        "0": "MP",
        "3": "DZ"
    },
    "4": {
        "8": "$ 333",
        "0": "$ 23.424",
        "13": "$ 222"
    },
    "2": {
        "0": "AL",
        "4": "AX"
    },
    "3": {
        "0": "true",
        "4": "true"
    },
    "5": {
        "15": "$ 2.541"
    },
    "6": {
        "16": "$  "
    },
    "7": {
        "16": "#c62828"
    },
    "8": {
        "16": "2020-05-19 00:00:00"
    }
}

现在我的 JSON 响应是一个具有特定索引的关联数组(JSON 对象)(索引不按顺序排列)。jexcel 是否支持任何类型的功能?

标签: javascriptjqueryjsonajaxjexcelapi

解决方案


试试下面的代码。文档中似乎有错误。

<div id="spreadsheet2"></div>

<script>
    jexcel(document.getElementById('spreadsheet2'), {
        url:'/URL-TO-YOUR-JSON.json',
        columns: [
            { type:'text', width:'300px' },
            { type:'text', width:'100px' },
         ]
    });
</script>
</html>

推荐阅读