表格未显示ajax数据

问题描述 投票:0回答:1

我无法获得“表格”来显示带有数据的表格。已在Chrome和Edge上进行过测试。

main.js

let jsonURL = './readAllUsers.php';

var table = new Tabulator("#example-table", {
    ajaxURL: jsonURL,
    ajaxResponse: (url, params, response) => {
        console.log(response.data);
        return response.data;
    }

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Table</title>
    <link href="/node_modules/tabulator-tables/dist/css/tabulator.css" rel="stylesheet">
</head>
<body>
    <div id="example-table"></div>

    <script type="text/javascript" src="/node_modules/tabulator-tables/dist/js/tabulator.js"></script>
    <script src="./main.js"></script>
</body>
</html>

readAllUsers.php返回json数据...如果我检查上述'ajaxResponse'的控制台日志输出,我会看到测试数据:

Array(6)
0: {id: "1", firstName: "Lou", lastName: "Pieters", email: "[email protected]", phone: "0123456789", …}
1: {id: "2", firstName: "John", lastName: "Snow", email: "[email protected]", phone: "0129871234", …}
2: {id: "3", firstName: "Buck", lastName: "Rogers", email: "[email protected]", phone: "0129986677", …}
3: {id: "4", firstName: "Tom", lastName: "Tom", email: "[email protected]", phone: "0129986767", …}
4: {id: "5", firstName: "Dick", lastName: "Richards", email: "[email protected]", phone: "0129983344", …}
5: {id: "6", firstName: "Harry", lastName: "Potter", email: "[email protected]", phone: "012999900", …}
length: 6
__proto__: Array(0) 
javascript tabulator
1个回答
0
投票

确定-我添加了一个属性,它现在可以工作(无需指定列)。我添加了“ autoColumns:true”。现在它将数据和字段名称显示为标题。感谢Trace的所有努力。(我实际上以为'autoColumns'默认为'true')。

© www.soinside.com 2019 - 2024. All rights reserved.