How to repeat the below JSON without write for loop using only ng-repeat
$scope.cart = {
"product": [
{
"HH_STYLENUM": "2204-RYP",
"SIZE_QTY": [
{ "QTY": "11", "SIZE": "XS" },
{ "QTY": "11", "SIZE": "XL" },
{ "QTY": "111", "SIZE": "S" },
{ "QTY": "111", "SIZE": "M" },
{ "QTY": "111", "SIZE": "L" }
],
"HH_CUSTID": "2919",
"HH_ADDCART_UNITPRICE": "11.5",
"HH_ADDCART_NO": "188",
"HH_ADDCART_DATE": "2014-12-10 00:25:07.0",
"HH_ADDCART_STATUS": "CART",
"HH_COLORID": "15991"
},
{
"HH_STYLENUM": "2204-HHSH",
"SIZE_QTY": [
{ "QTY": "01", "SIZE": "XS" },
{ "QTY": "03", "SIZE": "XL" },
{ "QTY": "104", "SIZE": "S" },
{ "QTY": "51", "SIZE": "M" },
{ "QTY": "31", "SIZE": "L" }
],
"HH_CUSTID": "2919",
"HH_ADDCART_UNITPRICE": "11.5",
"HH_ADDCART_NO": "188",
"HH_ADDCART_DATE": "2014-12-10 00:25:07.0",
"HH_ADDCART_STATUS": "CART",
"HH_COLORID": "15991"
}
]
};
Based on your comments... you could use two ng-repeats. One to loop over cart.product and within that ng-repeat, another ng-repeat to loop over SIZE_QTY
<div ng-repeat="product in cart.product">
<p ng-repeat="size in product.SIZE_QTY">{{size.SIZE}}</p>
Related
enter image description here
Parse error on line 15:
...,
"Qty": 3
},
{
"Amount":
--------------------^
Expecting 'STRING', got '{'
I don't know how to format the code for stack overflow but this is the JSON array I'm trying to put together
{
"MetaData": {
"CreateTime": "2019-05-16T18:13:13-08:00",
"LastUpdatedTime": "2019-05-16T18:13:45-08:00"
},
"Line": [{
"Amount": 135,
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"ItemRef": {
"value": "1",
"name": "LV"
},
"Qty": 3
},
{
"Amount": 135,
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"ItemRef": {
"value": "1",
"name": "LV"
},
"Qty": 3
} }
],
"CustomerRef": {
"value": "20"
}
}
The solution is probably simple
{
"MetaData": {
"CreateTime": "2019-05-16T18:13:13-08:00",
"LastUpdatedTime": "2019-05-16T18:13:45-08:00"
},
"Line": [
{
"Amount": 135,
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"ItemRef": {
"value": "1",
"name": "LV"
},
"Qty": 3
} <--- MISSING BRACE HERE
},
{
"Amount": 135,
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"ItemRef": {
"value": "1",
"name": "LV"
},
"Qty": 3
}
}
],
"CustomerRef": {
"value": "20"
}
}
I am new to working with JSON data. I am having difficulty on how to return back bicycles that have a color of "Blue". Using JSONPath.
The following example JSON file.
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
"bicycle": [
{
"price": 19.95
"color": [
"red"
],
},
{
"price": 20.99
"color": [
"blue",
"Green"
],
},
]
}
}
I have tried to use the following filter but it doesn't work.
$.store.bicycle[?(#.color=='blue')]
Any ideas to how to get this to work and only return the price of bicycles that are Blue?
Any information is greatly welcomed.
The JSON Data is
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
}],
"bicycle": [
{
"price": 19.95,
"color": [
"red"
]
},
{
"price": 20.99,
"color": [
"blue",
"Green"
]
}
]
}
}
The JSONPath is
$.store.bicycle[?(#.color.indexOf('blue') != -1)]
I'm trying to loop through a multi-dimensional array to get properties of products that are part of line items. They look basically like this: (I did a json_encode so it would be easier to read)
[{
"rcpt": "email#email.com",
"vars": [{
"name": "SYSTEM",
"content": "Bikes"
}, {
"name": "CUSTOMERSERVICE",
"content": "(855-553-4889)"
}, {
"name": "IMAGE",
"content": "http:\/\/www.url.com\/assets\/images\/chicago\/email\/dear_member.jpg"
}, {
"name": "LINKCOLOR",
"content": "#3db7e4"
}, {
"name": "FACEBOOK",
"content": "Bikes"
}, {
"name": "TWITTER",
"content": "Bikes"
}, {
"name": "INSTAGRAM",
"content": "Bikes"
}, {
"name": "CLOSING",
"content": "Greetings"
}, {
"name": "item",
"content": [{
"lineItem": 1,
"id": "3",
"name": "24-Hour Pass Gift Certificate",
"quantity": 2,
"nameShort": "24-Hour",
"type": "Gift Certificate",
"image": "24hour_blank.jpg",
"price": "9.95",
"total": "19.90",
"taxable": false,
"giftCertificates": {
"3204": {
"id": "3204",
"redemptionNumber": "xxxxx",
"type": "24-Hour"
},
"3205": {
"id": "3205",
"redemptionNumber": "xxxxx",
"type": "24-Hour"
}
}
}, {
"lineItem": 2,
"id": "1",
"name": "Annual Membership Gift Certificate",
"quantity": 2,
"nameShort": "Annual",
"type": "Gift Certificate",
"image": "annual_blank.jpg",
"price": "75.00",
"total": "150.00",
"taxable": false,
"giftCertificates": {
"892": {
"id": "892",
"redemptionNumber": "xxxxxx",
"type": "Annual"
},
"893": {
"id": "893",
"redemptionNumber": "xxxxx",
"type": "Annual"
}
}
}]
}, {
"name": "orderID",
"content": 1220
}, {
"name": "giftMessage",
"content": false
}, {
"name": "email",
"content": "email#email.com"
}, {
"name": "transactionDate",
"content": "12\/23\/2015"
}, {
"name": "transactionTime",
"content": "12:21 pm"
}, {
"name": "salesTaxTotal",
"content": 0
}, {
"name": "salesTaxRatePercent",
"content": "6.250"
}, {
"name": "TransactionAmount",
"content": "169.90"
}, {
"name": "account_number",
"content": "XXXX1111"
}, {
"name": "card_type",
"content": "Visa"
}, {
"name": "firstName",
"content": "tetete"
}, {
"name": "lastName",
"content": "tethuhhu"
}, {
"name": "address",
"content": "295 Place St"
}, {
"name": "city",
"content": "Brooklyn"
}, {
"name": "state",
"content": "NY"
}, {
"name": "zip",
"content": "11238"
}, {
"name": "country",
"content": "US"
}, {
"name": "phone",
"content": "8888888888"
}, {
"name": "transactionId",
"content": "xxxxxx"
}, {
"name": "shipToFirstName",
"content": "tetete"
}, {
"name": "shipToLastName",
"content": "tethuhhu"
}, {
"name": "shipToAaddress",
"content": "295 Place St"
}, {
"name": "shipToCity",
"content": "Brooklyn"
}, {
"name": "shipToState",
"content": "NY"
}, {
"name": "shipToZipCode",
"content": "11238"
}, {
"name": "ShipToCountry",
"content": "US"
}, {
"name": "ShipToCountry",
"content": "US"
}]
}]
So I am trying to get a print out of each gift certificate's type and redemption number. When I iterate through {{ giftCertificates }} like this:
{{#each giftCertificates}}
{{type}} {{redemptionNumber}}
{{/each}}
I get one of the line items but not the other. I'm guessing maybe it is being overwritten when it loops through again? But I have also tried to loop through {{ item }} and grab {{ giftCertificates.type }} and {{ giftCertificates.redemptionNumber }} and that does not work either. What is the correct way to get all of these from each line item?
Thanks for your help.
I know this is a very old question, but:
you can use {{this.proprietyName}} to get the type and number:
{{#each giftCertificates}}
{{this.892.type}}
{{/each}}
do not forget to add this to the mandrill message o
"merge": true,
"merge_language": "handlebars",
Also, the data structure is not ideal:
giftCertificates[
{
"id": "892",
"redemptionNumber": "xxxxxx",
"type": "Annual"
},
{
"id": "893",
"redemptionNumber": "xxxxxx",
"type": "Annual"
}
]
would be easier to handle.
My scope data:
$scope.data =
"category": [{
"name": "cat1",
"behaviour": "normal",
"selected": 0,
"values": [{
"label": "define",
"count": 6
}]
}, {
"name": "cat2",
"behaviour": "normal",
"selected": 0,
"values": [{
"label": "type",
"count": 6
}]
}, {
"name": "Company",
"behaviour": "multi-select",
"selected": 0,
"values": [{
"label": "VW",
"count": 4
}, {
"label": "Renault",
"count": 1
}, {
"label": "Fiat",
"count": 1
}]
}, {
"name": "Make",
"behaviour": "multi-select",
"selected": 0,
"values": [{
"label": "Gold",
"count": 3
}]
}, {
"name": "Color",
"behaviour": "normal",
"selected": 0,
"values": [{
"label": "White",
"count": 3
}, {
"label": "Blue",
"count": 2
}, {
"label": "Green",
"count": 1
}]
}]
How can I access the "name":"value" without using indexes? as the data might grow and change and I don't want to assign an index value anywhere? I'd still want to filter such as:
| {name: 'Make'}: true)
in my mark up to show
So the json is incorrect, i corrected it (next time you can use this site to see if your json is valid JSONVALIDATOR)
If you want to access at value of the name do this
In your controller :
$scope.data = [
{
"name": "cat1",
"behaviour": "normal",
"selected": 0,
"values": [
{
"label": "define",
"count": 6
}
]
},
{
"name": "cat2",
"behaviour": "normal",
"selected": 0,
"values": [
{
"label": "type",
"count": 6
}
]
},
{
"name": "Company",
"behaviour": "multi-select",
"selected": 0,
"values": [
{
"label": "VW",
"count": 4
},
{
"label": "Renault",
"count": 1
},
{
"label": "Fiat",
"count": 1
}
]
},
{
"name": "Make",
"behaviour": "multi-select",
"selected": 0,
"values": [
{
"label": "Gold",
"count": 3
}
]
},
{
"name": "Color",
"behaviour": "normal",
"selected": 0,
"values": [
{
"label": "White",
"count": 3
},
{
"label": "Blue",
"count": 2
},
{
"label": "Green",
"count": 1
}
]
}
];
In your HTML
<div ng-repeat="d in data"> {{d.name}} </div>
If you want to display values of the object with the name 'Company' you can do this like in my working CodePen :
Just add a new ng-repeat :
<div ng-repeat="d in data"> {{d.name}}
<div ng-if="d.name == 'Company'" ng-repeat="da in d.values">{{da.label}}</div>
</div>
First off, the format of your data is not correct JSON format, run it through an online validator.
To access the element, you would simply be able to through:
<li ng-repeat="item in data">
{{ item.name }} {{ item.behaviour }} etc...
</li>
Get rid of category within $scope.data... just let it be an array like a typical JSON value.
I have the following object in my AngularJS Controller:
{"team":"1","name":"abc","age":"20"},
{"team":"1","name2":"def","age2":"21"},
{"team":"2","name":"ghi","age":"22"},
{"team":"2","name2":"jkl","age2":"23"},
I need to group the items into one array object, by the team key.
{
"team": [
{"name1":"abc","age1":"20", "name2":"def", "age2":"21"},
{"name1":"ghi","age1":"22", "name2":"jkl", "age2":"23"}
]
}
So I can later use the information like $scope.data.team[1].name2
EDIT: One Team always consists of 4 players by the way.
How would I do this?
edit: working plunkr for your needs: http://plnkr.co/edit/zxoOYV?p=preview
you should rearrange your structure. i.e. you could go for something like this:
{"team": [
{"players": [
{"name" : "abc", "age": 20},
{"name" : "def", "age": 34},
]},
{"players": [
{"name" : "abc", "age": 20},
{"name" : "def", "age": 34},
]}
]}
if you use this structure in your controller:
$scope.team = {...}
and use it in your html like:
<div ng-controller="TeamController">
<div ng-repeat="players in team">
<div ng-repeat="player in players">
<div>Name: {{player.name}}</div>
<div>Name: {{player.age}}</div>
</div>
</div>
</div>
so, for your example, i got the angular-schema-form working.
with the above structure the schema looks like this:
[
{
"type": "help",
"helpvalue": "<h4>Tabbed Array Example</h4><p>Tab arrays can have tabs to the left, top or right.</p>"
},
{
"key": "team",
"type": "tabarray",
"add": "New",
"remove": "Delete",
"style": {
"remove": "btn-danger"
},
"title": "value.name || 'Team '+$index",
"items": [
{
"key": "team[].players",
"title": "Players",
"items": [
{
"key": "team[].players[].name",
"title": "Name"
},
{
"key": "team[].players[].age",
"title": "Age"
}
]
}
]
},
{
"type": "submit",
"style": "btn-default",
"title": "OK"
}
]
and the corresponding schema:
{
"type": "object",
"title": "Team",
"properties": {
"team": {
"type": "array",
"items": {
"type": "object",
"properties": {
"players": {
"type": "array",
"maxItems": 4,
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
}
},
"required": [
"name",
"age"
]
}
}
},
"required": [
"players"
]
}
}
}
}