Given the JSON object (formData), I'm trying to loop through the object with AngularJS and output RealEstateInfo and PersonalTaxInfo. For the life of me, I can't seem to figure out how to get at the property name. Any ideas?
By the way, (key,value) does not work. key gives me the index number, value the entire object.
<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"
}]
}]
}]
In JSON, the “keys” must always be strings. Each of these pairs is conventionally referred to as a “property”.
AngularJS json FilterThe json filter converts a JavaScript object into a JSON string. This filter can be useful when debugging your applications. The JavaScript object can be any kind of JavaScript object.
Please have a look at this fiddle. http://jsfiddle.net/4UTHW/
ng-repeat="(key,value) in data"
using this syntax will assign the keys of an object to key
variable and values of those keys to value
variable.
Simplified the json structure for brevity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With