5

给定 JSON 对象(formData),我尝试使用 AngularJS 遍历该对象并输出RealEstateInfoPersonalTaxInfo。对于我的生活,我似乎无法弄清楚如何获得属性名称。有任何想法吗?

顺便说一句,(键,值)不起作用。key给了我索引号,为整个对象赋值。

<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"
        }]
    }]
}]
4

1 回答 1

5

请看看这个小提琴。http://jsfiddle.net/4UTHW/

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

使用此语法会将对象的键分配给key变量,并将这些键的值分配给value变量。

为简洁起见,简化了 json 结构。

于 2013-03-21T19:25:30.447 回答