未使用的类型使用对象更新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; }
}