У меня есть массив как

[{"contractID":1,"contractName":"test","supplierID":1,"supplierName":"test","productID":1,"productName":"test","uom":"each","quantity":1,"pricePerUOM":1,"totalPrice":1,"currency":"$","supplyByDate":"now","carrier":"FexEx","pickTo":"USA","shipTo":"USA","Trackingnumber":"test","signedBy":"buyer","pendingWith":"buyer","createdBy":"buyer","createdDate":"now","status":"closed","filler1":"","filler2":"","filler3":"","filler4":"","filler5":""},{"contractID":50,"contractName":"testinsert","supplierID":3,"supplierName":"testinsert","productID":1,"productName":"test","uom":"each","quantity":10,"pricePerUOM":10,"totalPrice":100,"currency":"$","supplyByDate":22112016,"carrier":null,"pickTo":null,"shipTo":null,"Trackingnumber":null,"signedBy":"buyer","pendingWith":"","createdBy":"buyer","createdDate":"22112016","status":"closed","filler1":null,"filler2":null,"filler3":null,"filler4":null,"filler5":null},{"contractID":60,"contractName":"testinsert","supplierID":3,"supplierName":"testinsert","productID":1,"productName":"test","uom":"each","quantity":10,"pricePerUOM":10,"totalPrice":100,"currency":"$","supplyByDate":22112016,"carrier":null,"pickTo":null,"shipTo":null,"Trackingnumber":null,"signedBy":"buyer","pendingWith":"","createdBy":"buyer","createdDate":"22112016","status":"closed","filler1":null,"filler2":null,"filler3":null,"filler4":null,"filler5":null}]

И он сохранен как $ scope.contractsDeply И я пытаюсь использовать с ng-repeat, но его данные отсутствуют.

<tbody>{{contractsDeply}}
                        <tr ng-repeat="contract in contractsDeply track by $index">
                            {{contract}}
                            <td>{{ contract.contractID }}</td>
                            <td>{{ contract.contractName }}</td>
                        </tr>
                        </tbody>

?????

0
Adarsh M Pallickal 26 Ноя 2016 в 11:07

3 ответа

Лучший ответ

< Сильный > HTML:

<body ng-app='app'>
  <div ng-controller="listController">
    <table class="table table-striped">
      <thead>
        <tr>
          <th ng-repeat="(key, value) in contractsDeply[0]">{{key | uppercase }}
          </th>
        </tr>
        <tbody>
          <tr ng-repeat="val in contractsDeply">
            <td ng-repeat="cell in val">
              <input type="text" ng-model="cell">
            </td>
          </tr>
        </tbody>
    </table>
  </div>
</body>

< Сильный > Контроллер:

var app = angular.module("app", []);

app.controller("listController", ["$scope", "$http",
  function($scope, $http) {

    $http.get('test.json').then(function(response) {
      $scope.contractsDeply = response.data;
      console.log($scope.contractsDeply);

    });

  }
]);

DEMO

0
Sajeetharan 26 Ноя 2016 в 08:35

Возможно, вам не хватает элемента таблицы. См. Пример.

<div ng-controller="myController as ctr">

                  <tbody>
                    <tr ng-repeat="contract in contractsDeply track by $index">
                        {{contract}}
                        <td>{{ contract.contractID }}</td>
                        <td>{{ contract.contractName }}</td>
                    </tr>
                    </tbody>
                 <p>
                 -------------------------
                 </p>   

                 <table>
                    <tr ng-repeat="contract in contractsDeply">
                        <td>{{ contract.contractID }}</td>
                        <td>{{ contract.contractName }}</td>
                    </tr>
                 </table>

</div>  
0
Turgay Gülmez 26 Ноя 2016 в 08:58

Html

<html>
<script src="library/angular.min.js"></script>
<script src="practice.js"></script>
<head>
</head>
<body ng-app="app">
<div ng-controller="test1">
<table>
<tbody>
    <tr ng-repeat="x in array">
        <td>{{x.contractID}}</td>
        <td>{{x.contractName}}</td>
        <td>{{x.supplierID}}</td>
        <td>{{x.productID}}</td>
    </tr>
</tbody>
</table>
</div>
</body>
</html>

Angularjs

angular.module('app',[]).controller('test1',function($scope){
    $scope.array=[{"contractID":1,"contractName":"test","supplierID":1,"supplierName":"test","productID":1,"productName":"test","uom":"each","quantity":1,"pricePerUOM":1,"totalPrice":1,"currency":"$","supplyByDate":"now","carrier":"FexEx","pickTo":"USA","shipTo":"USA","Trackingnumber":"test","signedBy":"buyer","pendingWith":"buyer","createdBy":"buyer","createdDate":"now","status":"closed","filler1":"","filler2":"","filler3":"","filler4":"","filler5":""},{"contractID":50,"contractName":"testinsert","supplierID":3,"supplierName":"testinsert","productID":1,"productName":"test","uom":"each","quantity":10,"pricePerUOM":10,"totalPrice":100,"currency":"$","supplyByDate":22112016,"carrier":null,"pickTo":null,"shipTo":null,"Trackingnumber":null,"signedBy":"buyer","pendingWith":"","createdBy":"buyer","createdDate":"22112016","status":"closed","filler1":null,"filler2":null,"filler3":null,"filler4":null,"filler5":null},{"contractID":60,"contractName":"testinsert","supplierID":3,"supplierName":"testinsert","productID":1,"productName":"test","uom":"each","quantity":10,"pricePerUOM":10,"totalPrice":100,"currency":"$","supplyByDate":22112016,"carrier":null,"pickTo":null,"shipTo":null,"Trackingnumber":null,"signedBy":"buyer","pendingWith":"","createdBy":"buyer","createdDate":"22112016","status":"closed","filler1":null,"filler2":null,"filler3":null,"filler4":null,"filler5":null}];   

});

Я сохраняю ваш массив в $ scope.array

0
shahab 26 Ноя 2016 в 09:49