angularJS + json file + object + .length
Здравствуйте.
Не могу понять почему ангуляр не считает кол-во чилдов в объекте. Код html:
<table class="table" ng-controller="ShowIndexStatistics as stats">
<tbody ng-repeat="indexSection in indexData">
<tr ng-repeat="account in indexSection.details.accounts">
<th ng-if="$first" ng-attr-rowspan="{{indexSection.details.accounts}}">
{{indexSection.name}} <small>({{indexSection.details.symbol}})</small>
<p>{{indexSection.details.accounts.length}}</p>
<pre>{{indexSection.details.accounts.length}}</pre>
</th>
<td>{{account.name}} <small>({{account.id}})</small></td>
</tr>
</tbody>
</table>
в контроллере:
var dbPath = "../../db/collection.json";
$scope.indexData = null;
$http({method: 'GET', url: dbPath}).
success(function (data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
$scope.indexData = data;
}).
error(function (data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
В итоге строка:
<pre>{{indexSection.details.accounts.length}}</pre>
Возвращает пустоту. Скажите, пожалуйста, что я делаю не так? |
Попробуйте обернуть $scope.indexData = data; в $scope.applay
|
Цитата:
|
Цитата:
Как оказалось для того что бы реализовать задачу, потребовалось изменить синтаксис в JSON файле. Данный положил в {} А вот перечень данных лежит в [] В итоге .length работает как и ожидается. |
| Часовой пояс GMT +3, время: 11:49. |