0

尝试使用 json2html 发出表格。得到错误TypeError: json2html is not a function

页眉有:

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Index</title>
    <link rel="stylesheet" href="/lib/bootstrap/dist/css/bootstrap.css" />
    <link rel="stylesheet" href="/lib/jqueryui/jquery-ui.css" />
    <link rel="stylesheet" href="/lib/font-awesome/css/fontawesome.css" />

    <script src="/lib/jquery/dist/jquery.js"></script>
    <script src="/lib/jqueryui/jquery-ui.js"></script>
    <script src="/lib/font-awesome/js/fontawesome.js"></script>
    <script src="/lib/canvasjs/canvasjs.js"></script>
    <script src="/lib/json2html/json2html.js"></script>
    <script src="/lib/jquery.json2html/jquery.json2html.js"></script>

    <link rel="stylesheet" href="/css/site.css" />
</head>

文件路径/lib/json2html/json2html.js/lib/jquery.json2html/jquery.json2html.js使用 ctrl-shift-i 确认

我最初希望执行的方法是:

$("#tableContainer").html(json2html(data, transform));

TypeError: json2html is not a function
at Object.layer2CallbackHandler [as callback] (https://localhost:44388/JsonChartJs:306:35)
at Object.success (https://localhost:44388/JsonChartJs:220:41)
at fire (c:\users\lukem\source\ctrack.dashboard\ctrack.dashboard\wwwroot\lib\jquery\dist\jquery.js:3268:32)
at Object.fireWith [as resolveWith] (c:\users\lukem\source\ctrack.dashboard\ctrack.dashboard\wwwroot\lib\jquery\dist\jquery.js:3398:8)
at done (c:\users\lukem\source\ctrack.dashboard\ctrack.dashboard\wwwroot\lib\jquery\dist\jquery.js:9305:15)
at XMLHttpRequest.<anonymous> (c:\users\lukem\source\ctrack.dashboard\ctrack.dashboard\wwwroot\lib\jquery\dist\jquery.js:9548:10)

我也尝试过这个基于json2html 页面上的 jquery 示例

$("#tableContainer").json2html(data, transform);

TypeError: $(...).json2html is not a function
at Object.layer2CallbackHandler [as callback] (https://localhost:44388/JsonChartJs:306:30)
at Object.success (https://localhost:44388/JsonChartJs:220:41)
at fire (c:\users\lukem\source\ctrack.dashboard\ctrack.dashboard\wwwroot\lib\jquery\dist\jquery.js:3268:32)
at Object.fireWith [as resolveWith] (c:\users\lukem\source\ctrack.dashboard\ctrack.dashboard\wwwroot\lib\jquery\dist\jquery.js:3398:8)
at done (c:\users\lukem\source\ctrack.dashboard\ctrack.dashboard\wwwroot\lib\jquery\dist\jquery.js:9305:15)
at XMLHttpRequest.<anonymous> (c:\users\lukem\source\ctrack.dashboard\ctrack.dashboard\wwwroot\lib\jquery\dist\jquery.js:9548:10)

很明显我以错误的方式加载这些。什么是正确的方法?

4

1 回答 1

0

如果您想使用 json2html 的 jquery 插件,您还需要将它包含在您的标题中

<script src="/lib/json2html/json2html.js"></script>
<script src="/lib/json2html/jquery.json2html.js"></script>

这应该使您能够使用以下内容

$("#tableContainer").json2html(data, transform);

否则,您可以像这样使用 json2html 的本机调用

$("#tableContainer").html(json2html.transform(data, transform));

因为 json2html 是一个对象而不是一个函数

于 2019-10-17T21:04:31.417 回答