Angularjs 为什么web服务返回的数据不显示在表中?
我在项目中使用anguraljs 1.6 我从web服务读取数据,需要在表中显示返回的数据 以下是我的http ajax调用:Angularjs 为什么web服务返回的数据不显示在表中?,angularjs,Angularjs,我在项目中使用anguraljs 1.6 我从web服务读取数据,需要在表中显示返回的数据 以下是我的http ajax调用: $http.get("../../Services/ReportDepartmentService.asmx/GetRecords").then(function (response) { $scope.report = response.data; }); 下面是从web服务返回的数据示例: "<?xml version="
$http.get("../../Services/ReportDepartmentService.asmx/GetRecords").then(function (response) {
$scope.report = response.data;
});
下面是从web服务返回的数据示例:
"<?xml version="1.0" encoding="utf-8"?>
<ArrayOfDepartmentReport xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://localhost/services">
<DepartmentReport>
<IncidentId>140609</IncidentId>
<JunctionId>1</JunctionId>
<PropType>Data1</PropType>
<Damage>Data2</Damage>
<UserName>John1</UserName>
<ContractNO>10040/10</ContractNO>
<FixName>Data3</FixName>
<TimeStart>14:31</TimeStart>
<TimeDue>17:31</TimeDue>
<TimeEnd>14:38</TimeEnd>
<StatusID>1</StatusID>
<StatusText>End</StatusText>
<Priority>High</Priority>
<Notes />
<IncidentFactor />
<Description />
<DtStartPlus>2017-01-18T14:31:00</DtStartPlus>
<DtDuePlus>2017-01-18T17:31:00</DtDuePlus>
<DtEnd>2017-01-18T14:38:00</DtEnd>
</DepartmentReport>
<DepartmentReport>
<IncidentId>140609</IncidentId>
<JunctionId>1</JunctionId>
<PropType>Data10</PropType>
<Damage>Data20</Damage>
<UserName>Max1</UserName>
<ContractNO>10040/10</ContractNO>
<FixName>Data30</FixName>
<TimeStart>14:31</TimeStart>
<TimeDue>17:31</TimeDue>
<TimeEnd>14:38</TimeEnd>
<StatusID>1</StatusID>
<StatusText>End</StatusText>
<Priority>High</Priority>
<Notes />
<IncidentFactor />
<Description>Description1</Description>
<DtStartPlus>2017-01-30T17:39:00</DtStartPlus>
<DtDuePlus>2017-01-30T20:39:00</DtDuePlus>
<DtEnd>2017-01-30T18:34:00</DtEnd>
</DepartmentReport>
</ArrayOfDepartmentReport>"
”
140609
1.
数据1
数据2
约翰1
10040/10
数据3
14:31
17:31
14:38
1.
终止
高的
2017-01-18T14:31:00
2017-01-18T17:31:00
2017-01-18T14:38:00
140609
1.
数据10
数据20
Max1
10040/10
数据30
14:31
17:31
14:38
1.
终止
高的
说明1
2017-01-30T17:39:00
2017-01-30T20:39:00
2017-01-30T18:34:00
"
正如您所看到的,它以XML格式返回
以下是表格:
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Credit</th>
<th>Semester</th>
</tr>
</thead>
<tbody><tr ng-repeat="record in report track by $index">
<td>{{record.IncidentId}}</td>
<td>{{record.JunctionId}}</td>
<td>{{record.PropType}}</td>
<td>{{record.Damage}}</td>
</tr>
</tbody>
</table>
身份证件
名称
信用
学期
{{record.IncidentId}
{{record.JunctionId}
{{record.PropType}
{{record.Damage}
但当我试图在表中显示数据时,它不会显示
我估计不会显示记录,因为从web服务返回的数据是XML格式而不是JSON格式
您知道如何在上表中显示数据吗?您必须使用一些js库(例如X2JS)将获得的XML数据转换为JSON格式 在控制器中尝试以下操作:
var vm = this;
var x2js = new X2JS();
var dataAsJson = x2js.xml_str2json(xmlData);
vm.report = dataAsJson.ArrayOfDepartmentReport.DepartmentReport;
这是一把小提琴:
希望这对你有用:-)你猜对了!AngularJS需要JSON来操作。您需要搜索一个库来将XML转换为JSON。使用XML->JSON转换器可以解决您的需要:)