未使用的类型使用对象更新dataTable时出错 [英] Uncaught type Error while updating the dataTable using an object

查看:56
本文介绍了未使用的类型使用对象更新dataTable时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试更新html页面中的数据表,同时这样做,我得到'未捕获的TypeError:undefined不是函数。不明白为什么我收到这个错误。感谢任何帮助。



这是我的代码



Hi,

I am trying to update datatable in an html page and while doing so, I am getting 'Uncaught TypeError: undefined is not a function". Not understanding why I am getting this error. Any Help is appreciated.

Here is my code

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Device List</title>
        <style>
            body {
                font-family: 'Segoe UI', Arial, Helvetica, sans-serif;
                font-size: 16px;
            }
            #stockTable table {
                border-collapse: collapse;
            }
            #stockTable table th, #stockTable table td {
                padding: 2px 6px;
            }
            #stockTable table td {
                text-align: right;
            }
            #stockTable .loading td {
                text-align: left;
            }
        </style>
         <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
        <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
        <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css"/>

          <!--Script references. -->
        <!--Reference the jQuery library. -->
        <script type="text/javascript" src="Scripts/jquery-1.6.4.js" ></script>
        <!--Reference the SignalR library. -->
        <!--Reference the SignalR library. -->
        <script src="Scripts/jquery.signalR-2.1.2.min.js"></script>
        <script>"http://localhost:8080/signalr/hubs"</script>
    </head>
<body>
    <h1>BLE Device List</h1>
    <div class="DeviceDataContainer">
    <input type="button" id="GetDeviceData" value="GetDeviceData" />
    <table id="example">
        <thead>
            <tr><th>DeviceName</th><th>IPAddress</th></tr>
        </thead>
        <tbody>
        </tbody>
    </table>
   </div>


    <script type="text/javascript">

            //Set the hubs URL for the connection
            var url = 'http://localhost:8080/signalr';

            var connection = $.hubConnection(url);

            // Declare a proxy to reference the hub.
            var hubProxy = connection.createHubProxy('HubClass');

            hubProxy.on('DeviceDataResults', processDeviceDataResults);

            connection.start().done(function () {
                $("#GetDeviceData").click(function() {

                    hubProxy.invoke('GetDeviceData');
                });


            });

            function processDeviceDataResults(results) {

//I am seeing the error in the below line, the results contains the deviceName and ipaddress.
                $('#example').dataTable({
                    "aaData": results
                });

            };
        </script>

</body>
</html>









这个是结果对象中的数据:





This is the data in results object:

public class DeviceData
   {
       public string DeviceName { get; set; }
       public string IPAddress { get; set; }

   }

推荐答案

.hubConnection(url);

//声明代理以引用集线器。
var hubProxy = connection.createHubProxy('HubClass');

hubProxy.on('DeviceDataResults',processDeviceDataResults);

connection.start()。done(function(){
.hubConnection(url); // Declare a proxy to reference the hub. var hubProxy = connection.createHubProxy('HubClass'); hubProxy.on('DeviceDataResults', processDeviceDataResults); connection.start().done(function () {


(#GetDeviceData)。click(function(){

hubProxy.invoke('GetDeviceData');
});


});

函数processDeviceDataResults(results){

//我在下面的行中看到错误,结果包含deviceName和ipaddress。
("#GetDeviceData").click(function() { hubProxy.invoke('GetDeviceData'); }); }); function processDeviceDataResults(results) { //I am seeing the error in the below line, the results contains the deviceName and ipaddress.


('#example')。dataTable({
aaData:results
});

};
< / script >

< / body >
< / html >
('#example').dataTable({ "aaData": results }); }; </script> </body> </html>









这个是结果对象中的数据:





This is the data in results object:

public class DeviceData
   {
       public string DeviceName { get; set; }
       public string IPAddress { get; set; }

   }


这篇关于未使用的类型使用对象更新dataTable时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆