来自http post的返回的json响应数据如下:
{"ResponseData":[["AUSTRALIA","VICTORIA","MELBOURNE"],["AUSTRALIA ","NEW SOUTH WALES","SYDNEY"]]}
控制器代码:
app.controller('tableController', function ($scope)
{
$scope.customerTable = [];
$scope.getTable = function ()
{
$http.get('getTable.do').success(function (data)
{
$scope.customerTable = data;
});
};
});
这是我的div:
<div ng-controller="tableController">
<p> Click <a ng-click="getTable()">here</a> to load data.</p>
<table>
<tr>
<th>COUNTRIES</th>
<th>STATES</th>
<th>CITIES</th>
</tr>
<tr ng-repeat="data in customerTable">
<td>{{data[0]}}</td>
<td>{{data[1]}}</td>
<td>{{data[2]}}</td>
</tr>
</table>
</div>
当我使用ng-repeat加载数据时,它只显示为{{data.country}}而不是实际值。没有服务器端问题,因为我得到了回复,但无法理解为什么数据没有显示在表中?
答案 0 :(得分:3)
{"ResponseData":
[
["AUSTRALIA","VICTORIA","MELBOURNE"],
["AUSTRALIA ","NEW SOUTH WALES","SYDNEY"]]
}
它是一个包含数组ResponseData的对象,它包含两个包含3个字符串的数组。你应该这样做:
app.controller('tableController', function ($scope)
{
$scope.customerTable = [];
$scope.getTable = function ()
{
$http.get('getTable.do').success(function (data)
{
$scope.customerTable = data.ResponseData;
});
};
});
和HTML:
<div ng-controller="tableController">
<p> Click <a ng-click="getTable()">here</a> to load data.</p>
<table>
<tr>
<th>COUNTRIES</th>
<th>STATES</th>
<th>CITIES</th>
</tr>
<tr ng-repeat="data in customerTable">
<td>{{data[0]}}</td>
<td>{{data[1]}}</td>
<td>{{data[2]}}</td>
</tr>
</table>
</div>
答案 1 :(得分:1)
试试这个, 控制器: -
app.controller('tableController', function ($scope)
{
$scope.customerTable = [];
$scope.getTable = function ()
{
$http.get('getTable.do').success(function (data)
{
$scope.customerTable = data["ResponseData"];
});
};
});
HTML: -
<div ng-controller="tableController">
<p> Click <a ng-click="getTable()">here</a> to load data.</p>
<table>
<tr>
<th>COUNTRIES</th>
<th>STATES</th>
<th>CITIES</th>
</tr>
<tr ng-repeat="data in customerTable">
<td>{{data[0]}}</td>
<td>{{data[1]}}</td>
<td>{{data[2]}}</td>
</tr>
</table>
</div>1