如何使用 AngularJS 和 JsonResult ASP.NET MVC 使用 ng-repeat 列出值
How to list values using ng-repeat using AngularJS and JsonResult ASP.NET MVC
我正在尝试从我的 JsonResult 控制器呈现一个列表。没关系,我在我的 Angular 服务中收到数据,但无法使用 ng-repeat 将其呈现在列表中。它呈现了一个很大的空列表。
当数据不是列表时,它可以工作。
Angular。
Debug
var app = angular.module('FileApp', []);
app.service('ngFileService', function ($http) {
this.getFileByFileCode = function (fileCodigo) {
var response = $http.get("/Files/GetFile?fileCodigo=" + fileCodigo);
return response;
};
});
app.controller('ngFileController', function ($scope, ngFileService) {
$scope.filterFileCode = "";
$scope.getFilteredFile = function () {
var promise = ngFileService.getFileByFileCode($scope.filterFileCode);
promise.then(function (resp) {
$scope.File = resp.data;
$scope.Message = "Call is Completed Successfully";
}, function (err) {
$scope.Message = "Call Failed " + err.status;
});
};
});
HTML
<tr>
<td>Enter Search Value:</td>
<td><input type="text" ng-model="filterFileCode" class="form-
control" ng-change="getFilteredFile()" /></td>
</tr>
<table class="table table-bordered table-condensed table-striped">
<thead>
<tr>
<th>Documentos Gerais File</th>
<th></th>
<th>CTB</th>
<th>COM</th>
<th>Site</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="f in File">
<td>Documentos</td>
<td>{{f.FileCTB}}</td>
<td>{{f.FileCOM}}</td>
<td>{{f.FileSite}}</td>
</tr>
</tbody>
</table>
Erro
我希望呈现布尔值列表。
**DataCriacao: "/Date(-62135596800000)/"
DataFim: "06/07/2018"
DataInicio: "26/06/2018"
DescricaoServico: null
FileCOM: (2) [true, false]
FileCTB: (2) [false, false]
FileCodigo: 190562
FileCodigoId: 0
FileCodigoNv: null
FileMimeType: null
FileSite: (2) [false, false]**
[已解决]
我找到了制作上述解决方案的解决方案:
<tbody>
<tr>
<td>Documentos</td>
<td>Comandos</td>
<td><span ng-repeat="(key, value) in File.FileCTB track by $index">
{{value}}</span></td>
<td><span ng-repeat="(key, value) in File.FileCOM track by $index">
{{value}}</span></td>
<td><span ng-repeat="(key, value) in File.FileSite track by $index">
{{value}}</span></td>
</tr>
</tbody>
我解决了将所有日期存储在 viewModel 对象中的问题:
DataCriacao: "/Date(-62135596800000)/"
DataFim: "06/07/2018"
DataInicio: "26/06/2018"
DescricaoServico: null
FileCOM: (2) [true, false]
FileCTB: (2) [false, false]
FileCodigo: 190562
FileCodigoId: 0
FileCodigoNv: null
FileMimeType: null
FileSite: (2) [false, false]
因此,我只能在集合或数组的属性中进行迭代。
我正在尝试从我的 JsonResult 控制器呈现一个列表。没关系,我在我的 Angular 服务中收到数据,但无法使用 ng-repeat 将其呈现在列表中。它呈现了一个很大的空列表。 当数据不是列表时,它可以工作。
Angular。 Debug
var app = angular.module('FileApp', []);
app.service('ngFileService', function ($http) {
this.getFileByFileCode = function (fileCodigo) {
var response = $http.get("/Files/GetFile?fileCodigo=" + fileCodigo);
return response;
};
});
app.controller('ngFileController', function ($scope, ngFileService) {
$scope.filterFileCode = "";
$scope.getFilteredFile = function () {
var promise = ngFileService.getFileByFileCode($scope.filterFileCode);
promise.then(function (resp) {
$scope.File = resp.data;
$scope.Message = "Call is Completed Successfully";
}, function (err) {
$scope.Message = "Call Failed " + err.status;
});
};
});
HTML
<tr>
<td>Enter Search Value:</td>
<td><input type="text" ng-model="filterFileCode" class="form-
control" ng-change="getFilteredFile()" /></td>
</tr>
<table class="table table-bordered table-condensed table-striped">
<thead>
<tr>
<th>Documentos Gerais File</th>
<th></th>
<th>CTB</th>
<th>COM</th>
<th>Site</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="f in File">
<td>Documentos</td>
<td>{{f.FileCTB}}</td>
<td>{{f.FileCOM}}</td>
<td>{{f.FileSite}}</td>
</tr>
</tbody>
</table>
Erro
我希望呈现布尔值列表。
**DataCriacao: "/Date(-62135596800000)/"
DataFim: "06/07/2018"
DataInicio: "26/06/2018"
DescricaoServico: null
FileCOM: (2) [true, false]
FileCTB: (2) [false, false]
FileCodigo: 190562
FileCodigoId: 0
FileCodigoNv: null
FileMimeType: null
FileSite: (2) [false, false]**
[已解决] 我找到了制作上述解决方案的解决方案:
<tbody>
<tr>
<td>Documentos</td>
<td>Comandos</td>
<td><span ng-repeat="(key, value) in File.FileCTB track by $index">
{{value}}</span></td>
<td><span ng-repeat="(key, value) in File.FileCOM track by $index">
{{value}}</span></td>
<td><span ng-repeat="(key, value) in File.FileSite track by $index">
{{value}}</span></td>
</tr>
</tbody>
我解决了将所有日期存储在 viewModel 对象中的问题:
DataCriacao: "/Date(-62135596800000)/"
DataFim: "06/07/2018"
DataInicio: "26/06/2018"
DescricaoServico: null
FileCOM: (2) [true, false]
FileCTB: (2) [false, false]
FileCodigo: 190562
FileCodigoId: 0
FileCodigoNv: null
FileMimeType: null
FileSite: (2) [false, false]
因此,我只能在集合或数组的属性中进行迭代。