Angularjs 是否可能在ng repeat中附加结果?

Angularjs 是否可能在ng repeat中附加结果?,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,尝试使用AngularJS从Northwind数据集设置发票的简单集合。有几个单独的项目由同一OrderID连接-我想在同一个表中显示这些项目。这是否可能使用ng repeat,或者我必须找到另一个解决方案 以下是相关片段: app.controller('fetchData', function($scope, $http) { let dynamicContent = getParameterByName('q'); //checks if any parameter is pres

尝试使用AngularJS从Northwind数据集设置发票的简单集合。有几个单独的项目由同一OrderID连接-我想在同一个表中显示这些项目。这是否可能使用ng repeat,或者我必须找到另一个解决方案

以下是相关片段:

app.controller('fetchData', function($scope, $http) {
    let dynamicContent = getParameterByName('q'); //checks if any parameter is present in the URL
    if (dynamicContent) { //runs the fetching if parameter is present
    $scope.param = dynamicContent; //saves URL parameter, to be used with ng-if
    $http.get(BASE_URL+dynamicContent) //appends chosen parameter from URL to base URL
        .then(function(response) {
        $scope.rawData = response.data; //saves array returned from ODATA-source
    });
}});




<div ng-if="param == 'Invoices'">
   <div ng-repeat="invoice in rawData.value">
       <table class="table-responsive" id="invoice-items">
          <tr>
             <th>Item</th>
             <th>Cost</th>
             <th>Quantity</th>
             <th>Price</th>
          </tr>
          <tr class="item-row">
             <th>{{ invoice.ProductName }}</th>
             <th>${{ invoice.UnitPrice }} </th>
             <th>{{ invoice.Quantity }} </th>
             <th>${{ invoice.ExtendedPrice }} </th>
           </tr>
       </table>
   </div>
</div>
“ng repeat”通常只用于填写一个表格,如下所示:

<div ng-if="param == 'Invoices'">
   <table class="table-responsive" id="invoice-items">
      <tr>
         <th>Item</th>
         <th>Cost</th>
         <th>Quantity</th>
         <th>Price</th>
      </tr>
      <tr class="item-row" ng-repeat="invoice in rawData.value">
         <th>{{ invoice.ProductName }}</th>
         <th>${{ invoice.UnitPrice }} </th>
         <th>{{ invoice.Quantity }} </th>
         <th>${{ invoice.ExtendedPrice }} </th>
       </tr>
   </table>
</div>

项目
成本
量
价格
{{invoice.ProductName}
${{invoice.UnitPrice}
{{发票.数量}
${{invoice.ExtendedPrice}
最好在行中使用“ng repeat”,而不是在表标记中使用。

我采取了以下措施:

[{
        "PostalCode": "12209",
        "Country": "Germany",
        "Salesperson": "Margaret Peacock",
        "OrderID": 10692
    },
    {
        "PostalCode": "12208",
        "Country": "Germany",
        "Salesperson": "hulk",
        "OrderID": 10692
    },
    {
        "PostalCode": "485021",
        "Country": "US",
        "Salesperson": "Thor",
        "OrderID": 10693
    },
    {
        "PostalCode": "562032",
        "Country": "US",
        "Salesperson": "Spider Man",
        "OrderID": 10693
    }
]
  • 我在这里所做的是基于
    OrderID
    的组数组。我过去也曾达到同样的目标

    \uu.groupBy(res.data,'OrderID')

  • 然后迭代每个对象键并插入一个新数组
    $scope.arr

  • 然后嵌套
    ng repeat

    <div ng-repeat="orders in arr">
            <table class="table-responsive" id="invoice-items">
              <tr>
                 <th>PostalCode</th>
                 <th>Country</th>
                 <th>Salesperson</th>
                 <th>OrderID</th>
              </tr>
              <tr ng-repeat="data in orders" class="item-row">
                 <th>{{ data.PostalCode }}</th>
                 <th>{{ data.Country }} </th>
                 <th>{{ data.Salesperson }} </th>
                 <th>{{ data.OrderID }} </th>
               </tr>
           </table>
           <hr>
        </div>
    
    
    后酒精
    国家
    销售员
    订单编号
    {{data.PostalCode}
    {{data.Country}
    {{data.salessorn}
    {{data.OrderID}
    

    你能分享你的json结构吗?是的,这里有一个问题:问题是我使用相同的ng repeat来进一步显示其他字段(与此无关)。是否可以对JSON数据进行排序,并使用额外的ng repeat?感谢您的详细解释-它现在正在按预期工作!:)@拉尔斯帕泽尔:干杯,伙计!我的答案也是:P
    <div ng-repeat="orders in arr">
            <table class="table-responsive" id="invoice-items">
              <tr>
                 <th>PostalCode</th>
                 <th>Country</th>
                 <th>Salesperson</th>
                 <th>OrderID</th>
              </tr>
              <tr ng-repeat="data in orders" class="item-row">
                 <th>{{ data.PostalCode }}</th>
                 <th>{{ data.Country }} </th>
                 <th>{{ data.Salesperson }} </th>
                 <th>{{ data.OrderID }} </th>
               </tr>
           </table>
           <hr>
        </div>