从CSV文件导入数据

时间:2018-07-10 08:02:16

标签: javascript html getorgchart

我正在尝试使用init-from-csv.html(从演示文件中)导入* .csv。我下载了GetOrgChart zip文件,并将链接更改为实际的.js和.css文件。

这是我的代码:

<!DOCTYPE html> <html> <head>
    <title>OrgChart | Initialize From XML</title>

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="D:/Tools/GetOrgChart/getorgchart/getorgchart.js"></script>
    <link href="D:/Tools/GetOrgChart/getorgchart/getorgchart.css" rel="stylesheet" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>



    <style type="text/css">
        html, body {
            margin: 0px;
            padding: 0px;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }

        #people {
            width: 100%;
            height: 100%;
        }
    </style> </head> <body>
    <div id="people"></div>
    <script type="text/javascript">

        function convertToCsvJson(allText) {
            var allTextLines = allText.split(/\r\n|\n/);
            var headers = allTextLines[0].split(',');
            var lines = [];

            for (var i = 1; i < allTextLines.length; i++) {
                var data = allTextLines[i].split(',');
                if (data.length == headers.length) {

                    var tarr = {};
                    for (var j = 0; j < headers.length; j++) {
                        tarr[headers[j]] = data[j];
                    }
                    lines.push(tarr);
                }
            }

            return lines;
        }

        $.get("D:/Tools/GetOrgChart/ORG_Data.txt", function (source) {

            source = convertToCsvJson(source);

            var peopleElement = document.getElementById("people");
            var orgChart = new getOrgChart(peopleElement, {
                theme: "helen",
                primaryFields: ["name", "Job Title"],
                photoFields: ["Photo"],
                linkType: "M",
                enableEdit: false,
                enableDetailsView: false,
                dataSource: source
            });
        });
    </script> </body> </html>

打开HTML文件后,将不会加载该文件。我不确定自己做错了什么。

0 个答案:

没有答案