gpt4 book ai didi

javascript - 无法在 View 中显示数据

转载 作者:行者123 更新时间:2023-11-28 19:44:47 25 4
gpt4 key购买 nike

我无法在 View 中显示数据。我在 results.data 上看到 ajax 加载的结果,但无法显示结果。

JSON 数据是 -

[{
"locationId": 14,
"name": "coin"
},
{
"locationId": 11,
"name": "coop"
},
{
"locationId": 5,
"name": "dxd"
},
{
"locationId": 15,
"name": "dxd2"
},
{
"locationId": 1017,
"name": "inka"
},
{
"locationId": 16,
"name": "test-pinco"
},
{
"locationId": 13,
"name": "upimuim"
}]

查看

<div class="row">
<div class="col-md-2">
&nbsp;
</div>
<div class="col-md-8">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>LocationId</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="order in orders">
<td>
{{ locationId }}
</td>
<td>
{{ name }}
</td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-2">
&nbsp;
</div>
</div>

Controller

'use strict';
app.controller('locationsController', ['$scope', 'locationsService', function ($scope, locationsService) {

$scope.locations = [];

locationsService.getLocations().then(function (results) {

$scope.locations = results.data;

}, function (error) {
//alert(error.data.message);
});

}]);

服务

'use strict';
app.factory('locationsService', ['$http', function ($http) {

var serviceBase = 'http://localhost:4014/';
var locationsServiceFactory = {};

var _getLocations = function () {

return $http.get(serviceBase + 'api/locations').then(function (results) {
return results;
});
};

locationsServiceFactory.getLocations = _getLocations;

return locationsServiceFactory;

}]);

最佳答案

在 View 中尝试这个-

将 $scope.locations 替换为 $scope.orders,然后使用 order.locationID 和 order.name。

关于javascript - 无法在 View 中显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24488526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com