2
我在一些指導之後如何將angularjs整合到這個項目中。我正在尋找一種將數據寫入表格的更好方法。非常感激任何的幫助。在C#中將AngularJS與Signalr結合使用asp.net項目
控制器
public class RaceDayDisplayController : ApiControllerWithHub<RaceDayDisplayHub>
{
[HttpPost]
[Route("api/DoSomething")]
public HttpResponseMessage DoSomething(Rootobject model)
{
Hub.Clients.All.LastSectional(model.sectionTimes[0].runners);
}
}
html頁面HTML寫入ID
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Display</title>
</head>
<body>
<h2>Real-Time Raceday Data</h2>
<table id="showData"></table>
<!--Script references. -->
<!--Reference the Angular library. -->
<script src="/Scripts/angular.js"></script>
<!--Reference the jQuery library. -->
<script src="/Scripts/jquery-1.10.2.min.js"></script>
<!--Reference the SignalR library. -->
<script src="/Scripts/jquery.signalR-2.1.2.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="/signalr/hubs"></script>
<script type="text/javascript">
$(function() {
var myHub = $.connection.raceDayDisplayHub;
try {
$.connection.hub.start();
myHub.on('LastSectional', function (runners) {
$("#showData tr").remove();
$('#showData').append('<tr><td width="150">Pos</td><td width="210">Name</td><td width="150">Margin</td><td width="150">Last Sectional</td><td width="150">Cumulative Times</td></tr>');
for (var i = 0; i < runners.length; i++) {
$('#showData').append('<tr><td>' + runners[i].position + '</td><td>' + runners[i].bookNumber + ' ' + runners[i].name + '</td><td>' + runners[i].margin + '</td><td>' + runners[i].sTime + '</td><td>' + runners[i].cumTime + '</td></tr>');
}
//var runners = JSON.stringify(runners)
//var app = angular.module('myApp', []);
//app.controller('customersCtrl', function ($scope) {
// $scope.runners = runners;
//});
});
} catch (e) {
alert(e.message);
}
});
</script>
</body>
</html>
您是否要求進行代碼審查?這不是Stack Overflow的主題。目前您在做什麼,是否存在實際問題? –