2013-03-21 79 views
5

鑑於JSON對象(FORMDATA),我通過與AngularJS和輸出RealEstateInfoPersonalTaxInfo對象試圖循環。對於我的生活,我似乎無法弄清楚如何查看房產名稱。有任何想法嗎?如何在AngularJS中訪問JSON屬性名稱(如果我不知道它是什麼)?

順便說一下,(鍵,值)不起作用。 給我索引號,整個對象。

<ul> 
    <li ng-repeat="item in formsData"> 
     {{item.value}} //What goes here to get "RealEstateInfo" the 1st loop, and "PersonalTaxInfo" the second loop? 
    </li> 
<ul> 

$scope.formData = [ 
{ 
    "RealEstateInfo": [ 
    { 
     "Group": "General", 
     "Fields": [ 
     { 
      "Name": "TitleType", 
      "Label": "Title Type", 
      "Type": "dropdown", 
     }, 
     { 
      "Name": "NameIfAvailable", 
      "Label": "Name if available", 
      "Type": "string" 
     }] 
    }, 
    { 
     "Group": "Personal", 
     "Fields": [ 
     { 
      "Name": "TitleType", 
      "Label": "Title Type", 
      "Type": "dropdown", 
     }, 
     { 
      "Name": "NameIfAvailable", 
      "Label": "Name if available", 
      "Type": "string" 
     }] 
    }] 
}, 
{ 
    "PersonalTaxInfo": [ 
    { 
     "Group": "General", 
     "Fields": [ 
     { 
      "Name": "TitleType", 
      "Label": "Title Type", 
      "Type": "dropdown", 
     }, 
     { 
      "Name": "NameIfAvailable", 
      "Label": "Name if available", 
      "Type": "string" 
     }] 
    }, 
    { 
     "Group": "PersonalInfo", 
     "Fields": [ 
     { 
      "Name": "TitleType", 
      "Label": "Title Type", 
      "Type": "dropdown", 
     }, 
     { 
      "Name": "NameIfAvailable", 
      "Label": "Name if available", 
      "Type": "string" 
     }] 
    }] 
}] 

回答

5

請看看這個小提琴。 http://jsfiddle.net/4UTHW/

ng-repeat="(key,value) in data" 

使用這種語法將對象的鍵分配給這些鍵的key變量和值到value變量。

爲簡潔起見,簡化了json結構。

+0

@ rajkamal-非常感謝!雖然我並不完全理解嵌套的ng-repeat概念,但這很奏效。我認爲,這是一個嵌套的標準編碼實踐中的每個循環... – 2013-03-21 19:38:46

+0

@rajkamal它是新的檢索屬性名稱雖然這,真的幫助! – ArifMustafa 2018-03-06 10:38:50

相關問題