我能夠建立一個asp.net Web API和腳手架到我的SQL Server數據庫。從sql server記錄返回似乎是JSON。該模型有幾個通過外鍵互相鏈接的表格,現在只有2條記錄。 Comp_Id = 1和2的結果,以我的本地API看起來像這樣:ASP.Net WEB API和ANGULAR不輸出一列與另一列
[{ 「ASSOC_INC_OFF」:[{ 「OFFICERINVOLVEDs」:[], 「AIO_ID」:1, 「COMP_ID」:1,」 「CINotice」:1,「LINK_TYPE」:null}],「CRITICALINCIDENTs」:[{「CIType」:「導致死亡或嚴重身體傷害的物理力量」,「CINotice」:null,「CIMonitorRolledOut1」 :NULL, 「CIOIMQuestions」:NULL, 「CICharged」:NULL, 「CIMonitor1」:NULL, 「CIMonitor2」:NULL, 「CINotes」:NULL, 「CIOfcCharges」:NULL, 「CIOutcome」:NULL, 「COMP_ID」:1 「RolledOut_DT」:NULL, 「CI_ID」:1, 「CINotice_DT」: 「2016-01-07T00:00:00」, 「CIOIMAllegNotes」:NULL, 「CIMonitorRolledOut2」:NULL, 「CIMonitorRolledOut3」:NULL, 「CIMonitorRolledOut4」 :NULL, 「CIMonitorRolledOut5」:NULL, 「CIMonitorRolledOut6」:NULL, 「CIMonitorRolledOut7」:空}], 「COMP_ID」:1, 「FILENUM」: 「情形1」, 「Received_DT」:「2016-01-21T00:00: 00" , 「Completed_DT」:空, 「OIMIntake_DT」:空, 「狀態」 :null,「Occurred_DT」:null,「ComplaintType」:null,「Source」:「Chiefs Office」,「Precinct」:「District 2」,「AddrCity」:null,「AddrState」:null,「AddrZip」:null 「CaseSummary」:空, 「IABNotified_DT」:空, 「ClosureLetSent_DT」:空, 「CaseType」:空, 「OIMOutcome」:空, 「InitialFinding」:空, 「ClosedFindings」:空, 「OIMRecFinding」:空」時間戳 「:空,」 部 「:」 DSD 「 」地址「:空, 」DECLINEREASON「:空, 」Filenum2「:空, 」Filenum3「:空, 」OIMDiscRev_DT「:空, 」OIMInvRev_DT「:空」 OIMInvRoute_DT「:null,」OIMDiscRoute_DT「:null,」CRORoute_DT「:null},{」ASSOC_INC_OFF「:[],」CRITICALINCIDENTs「:[{」CIType「:」主任/副參與射擊「,」CINotice「:null 「CIMonitorRolledOut1」:空, 「CIDAMonitored」:空, 「CIOIMQuestions」:空, 「CICharged」:空, 「CIMonitor1」:空, 「CIMonitor2」:空, 「CINotes」:空, 「CIOfcCharges」:空」 CIOutcome 「:空,」 COMP_ID 「:2,」 RolledOut_DT 「:空,」 CI_ID 「:2,」 CINotice_DT 「:空,」 CIOIMAllegNotes 「:空,」 CIMonitorRolledOut2 「:空,」 CIMonitorRolledOut3 「:空,」 CIMonitorRolledOut4" :空, 「CIMonitorRolledOut5」:空,「CIMonitorRol ledOut6 「:NULL,」 CIMonitorRolledOut7 「:空}],」 COMP_ID 「:2」,FILENUM 「:」 CW1" , 「Received_DT」: 「2016-01-03T00:00:00」, 「Completed_DT」:NULL,」 OIMIntake_DT「:null,」Status「:」Active「,」Occurred_DT「:null,」ComplaintType「:null,」Source「:」公民入場「,」區域「:」District 7「,」AddrCity「:null 「AddrState」:空, 「AddrZip」:空, 「CaseSummary」:空, 「IABNotified_DT」:空, 「ClosureLetSent_DT」:空, 「CaseType」: 「區 - 局」, 「OIMOutcome」: 「滿意」,」 InitialFinding「:」Formal「,」ClosedFindings「:null,」OIMRecFinding「:」Decline「,」timestamp「:null,」Department「:」DSD「,」Address「:null,」DeclineReason「 「Filenum2」:NULL, 「Filenum3」:NULL, 「OIMDiscRev_DT」:NULL, 「OIMInvRev_DT」:NULL, 「OIMInvRoute_DT」:NULL, 「OIMDiscRoute_DT」:NULL, 「CRORoute_DT」:空}]
我能夠將COMP_ID綁定到我的視圖,但是當我添加CIType時,會出現nothings。
的console.log($ scope.complaints)返回:
我的控制器看起來是這樣的:
app.controller('UpdateController', function ($scope, ComplaintService) {
getCities();
function getCities() {
ComplaintService.getCities()
.success(function (complaints) {
$scope.complaints = complaints;
})
.error(function (error) {
$scope.status = 'Unable to load customer data: ' + error.message;
});
}
});
我的服務是這樣的:
app.factory('ComplaintService', ['$http', function ($http){
var urlBase = 'http://localhost:63942/api';
var ComplaintService = {};
ComplaintService.getCities = function() {
return $http.get(urlBase+ '/complaints');
};
return ComplaintService;
}]);
和我的指標是這樣的:
<div class="row">
<div class="col-md-3" ng-controller="UpdateController">
<table class="table">
<tr>
<th>Id</th>
<th>CI TYPE</th>
<tr ng-repeat="a in complaints">
<td>{{a.COMP_ID}}</td>
<td>{{a.CIType }}</td>
</table>
</div>
我當然搞不清楚爲什麼我能渲染出只COMPID,但因爲它是所有在本地主機中列出的這個API內容不休息: ###/API /投訴。
尋找你的json非常困難,試着做console.log($ scope.complaints)(使用devtools來查看它),看看對象的實際外觀如何。 – thsorens
謝謝@thsorens,我這樣做,它說我有兩個對象的數組[2]。顯然,還有其他表格,如每個表格的Main對象的子集數組。有沒有訪問該「子數組」的方法?原因,爲什麼我稱它爲一個子集,因爲你必須通過點擊胡蘿蔔來擴展它。 – EPV
只要它的json,你隨時都可以。你自己下來。如果目標是將所有內容都放入一個列表中,則可能需要將不同子列表中的每個結果推送到用於顯示 – thsorens