2017-09-28 47 views
1

嗨我是Angular的新手,我需要一些比我有更多知識的人的反饋。我會詳細解釋我的問題。我必須創建一個表,在大多數情況下,我會使用ng-repeat循環訪問一組數據。然而,這次我的數據結構不同,API返回的是鍵而不是字符串和嵌套鍵,而不是數組,最後一層包含數組。Angular 1.5 ng-重複嵌套鍵而不是數組

數據

{ATLA: 
    {NECBTEST2012: 
    {FRMFM-HD: 
     [{date:"2017-09-27", run_rate:23}, 
     {date:"2017-09-28", run_rate:23}] 
     } 
     } 
    } 

HTML

<table > 
      <thead> 
      <tr> 
       <th> Market</th> 
       <th> </th> 
       <th>Average</th> 
      </tr> 
      <tr> 
       <th ><form > 
        <input type="text" class="form-control" placeholder="Filter market"> 
       </form></th> 
       <th> </th> 
       <th></th> 
      </tr> 
      </thead> 
      <tbody> 

      <tr ng-repeat-start="(key, value) in rc.runRate"> 
       <td>{{key}}</td> 
       <td> </td> 
       <td> </td> 
      </tr> 
      <tr ng-repeat-end class="slide-toggle-js"> 
       <td colspan="3" > 
        <div class="toggle-me" > 

        <table> 
         <thead> 
         <tr > 
          <th>Syscode</th> 
          <th>Network</th> 
          <th>Date</th> 
          <th>Average</th> 

         </tr> 
         <tr> 
          <th> 
           <form> 
            <input class="form-control" placeholder="Filter Syscode"> 
           </form> 
          </th> 
          <th> 
           <form> 
            <input class="form-control" placeholder="Filter Network"> 
           </form> 
          </th> 
          <th></th> 
          <th></th> 


         </tr> 
         </thead> 
         <tbody ng-cloak> 
         <tr ng-class-odd="'stripe-row-odd'" ng-class-even="'stripe-row-even'" ng-repeat="(key, value) in key"> 
          <td>{{key}}</td> 
          <td></td> 
          <td></td> 
          <td> </td> 

         </tr> 
         </tbody> 
        </table> 
        </div> 

所需的結果

在第NG-重複我能夠顯示第一個關鍵是ATLA在表格行中,然而,當我嘗試i時通過FRMFM-HD的下一個關鍵,我無法做到。我想學習併成爲一名更好的程序員,任何擁有更多知識和任何反饋的人都會很感激謝謝!

回答

2

第二次ng-repeat不應該是關鍵,實際上應該是關於你的數據持有者對象裏面的鍵值。

用rc.runRate [key]替換key。

鍵==>串

rc.runRate [鍵] ==>對象

<tr ng-class-odd="'stripe-row-odd'" ng-class-even="'stripe-row-even'" ng-repeat="(subkey, value) in rc.runRate[key]"> 
    <td>{{subkey}}</td> 
    <td></td> 
    <td></td> 
    <td> </td> 

</tr> 
+0

該工作完美,現在我可以顯示第二鍵是NECBTEST2012,如何我能我訪問第三個關鍵?我使用了value參數,但它顯示了所有的對象。感謝您花時間回答我的問題 – hwe

+0

您可以使用rc.runRate [key] [subkey] –