Javascript 从json到Angularjs的表

Javascript 从json到Angularjs的表,javascript,html,json,angularjs,Javascript,Html,Json,Angularjs,我创建了一个Angularjs应用程序,它通过RESTAPI获取json数据。 我需要从以下json格式获取表中的数据 { "121": { "buy":56, "sell":52, "customerId":63 } "122": { "buy":46, "sell":62, "customerId":13 } } 这里121和122是事务id。我试图以以下格式获取表中的数据,但我无法准确地确定如何显示事务ID及其

我创建了一个Angularjs应用程序,它通过RESTAPI获取json数据。 我需要从以下json格式获取表中的数据

{

"121":  {
    "buy":56,
    "sell":52,
    "customerId":63
    }

"122":
    {
    "buy":46,
    "sell":62,
    "customerId":13
    }
}
这里121和122是事务id。我试图以以下格式获取表中的数据,但我无法准确地确定如何显示事务ID及其相应的详细信息

以下是表格格式:

Transaction ID | Customer ID| Buy | Sell |
请告知。


项目
烙印
量
{{item.name}
{{item.brand}}
{{item.quantity}}

这可能会回答您的问题

这里的关键是使用ng repeat指令集合“中的
”(键,值)执行
ng repeat

您的桌子应该是>

<table>
  <thead>
    <tr>
      <th>Transaction ID</th>
      <th>Customer ID</th>
      <th>Buy</th>
      <th>Sell</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="(id, t) in transactions">
      <td>{{ id }}</td>
      <td>{{ t.customerId }}</td>
      <td>{{ t.buy }}</td>
      <td>{{ t.sell }}</td>
    </tr>
  </tbody>
</table>

事务ID
客户ID
购买
卖
{{id}
{{t.customerId}
{{t.buy}}
{{t.sell}}

下面是一个如何实现这一点的示例。您可以在控制器中创建名为customerData的模型,并在视图中使用它

<table ng-table class="table">
  <thead>
  <tr>

    <th>Transaction Id</th>
    <th>Cutomer Id</th>
    <th>Buy</th>
    <th>Sell</th>

  </tr>
  </thead>
<tr ng-repeat="customer in customerData">
    <td data-title="'TransactionId'">{{customer.transactionId}}</td>
    <td data-title="'CustomerId'">{{customer.customerId}}</td>
     <td data-title="'Buy'">{{customer.buy}}</td>
      <td data-title="'Sell'">{{customer.sell}}</td>
</tr>
</table>

这是一个完整的解决方案

请展示您的尝试。有很多教程可供学习。那么,你最后做了什么?@Anfelipe-我按照你提到的方式做了。成功了!!很高兴为您提供帮助,您可以将答案标记为正确,干杯!我的答案也是,但你先到了:)。这里有一把小提琴来完成它。。。
<table ng-table class="table">
  <thead>
  <tr>

    <th>Transaction Id</th>
    <th>Cutomer Id</th>
    <th>Buy</th>
    <th>Sell</th>

  </tr>
  </thead>
<tr ng-repeat="customer in customerData">
    <td data-title="'TransactionId'">{{customer.transactionId}}</td>
    <td data-title="'CustomerId'">{{customer.customerId}}</td>
     <td data-title="'Buy'">{{customer.buy}}</td>
      <td data-title="'Sell'">{{customer.sell}}</td>
</tr>
</table>
var app = angular.module('app', ['ngRoute']);
app.controller('HomeController',['$scope', function($scope) {
    var customerDataFromService={
      "121":  {
          "buy":56,
          "sell":52,
          "customerId":63
          },

      "122":
          {
          "buy":46,
          "sell":62,
          "customerId":13
          }
      };
      $scope.customerData=[];
      angular.forEach(customerDataFromService,function(value,key){
        var customer = {'transactionId' : key, 'customerId' :   value.customerId,'buy': value.buy,'sell':value.sell}
     $scope.customerData.push(customer);
      });
  }]);