简体   繁体   English

TypeError:json2html不是函数

[英]TypeError: json2html is not a function

Trying to use json2html to emit a table. 尝试使用json2html发出表。 Getting the error TypeError: json2html is not a function 收到错误TypeError:json2html不是函数

Page header has: 页面标题具有:

<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>

Path to files /lib/json2html/json2html.js and /lib/jquery.json2html/jquery.json2html.js confirmed using ctrl-shift-i 使用ctrl-shift-i确认的文件/lib/json2html/json2html.js/lib/jquery.json2html/jquery.json2html.js路径

The method I'm hoping to execute initially is: 我希望最初执行的方法是:

$("#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)

I've also tried this based on the jquery example at the json2html page 我还根据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)

It seems clear I'm loading these the wrong way. 显然我是用错误的方式加载这些。 What is the right way? 正确的方法是什么?

If you want to use the jquery plugin for json2html you're going to need to include it as well in your header 如果要对json2html使用jquery插件,则还需要在标头中包含它

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

Which should enable you to use the following 这应该使您可以使用以下内容

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

Otherwise you can use the native call for json2html like so 否则,您可以像这样使用json2html的本地调用

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

as json2html is an object NOT a function 因为json2html是对象而不是函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM