2

The JSON I am working with is below. I would like to be able to display url which is within contentInfo. I am able to display uniquKkey with my current angular code but I am unsure how to do it for anything that is an array within an array. I've tried a few things and got myself in a bit of a muddle so any help would be greatly appreciated. Essentially you type in an item number to a search box hit run and get that url back.

Thanks

JSON

 {
        "products": [
            {
                "uniqueKey": "trn:tesco:product:uuid:2cee5245-23a7-4d51-af6d-f63b3e157492",
                "TPNB": "050020430",
                "TPNC": "254876305",
                "GTIN14": "05000119001467",
                "sellingUnitOfMeasure": "EA",
                "marketingTextInfo": [
                    {
                        "text": "Baked beans in tomato sauce.\n",
                        "source": "Sonetto"
                    }
                ],
                "contentInfo": [
                    {
                        "url": "http://img.tesco.com/Groceries/pi/467/5000119001467/IDShot_90x90.jpg",
                        "default": "Y",
                        "source": "Sonetto",
                        "status": "",
                        "type": ""
                    },
                    {
                        "url": "http://img.tesco.com/Groceries/pi/467/5000119001467/IDShot_60x60.jpg",
                        "default": "N",
                        "source": "Sonetto",
                        "status": "",
                        "type": ""
                    },
                    {
                        "url": "http://img.tesco.com/Groceries/pi/467/5000119001467/IDShot_110x110.jpg",
                        "default": "N",
                        "source": "Sonetto",
                        "status": "",
                        "type": ""
                    },
                    {
                        "url": "http://img.tesco.com/Groceries/pi/467/5000119001467/IDShot_225x225.jpg",
                        "default": "N",
                        "source": "Sonetto",
                        "status": "",
                        "type": ""
                    },
                    {
                        "url": "http://img.tesco.com/Groceries/pi/467/5000119001467/IDShot_77x92.jpg",
                        "default": "N",
                        "source": "Sonetto",
                        "status": "",
                        "type": ""
                    },
                    {
                        "url": "http://img.tesco.com/Groceries/pi/467/5000119001467/IDShot_126x150.jpg",
                        "default": "N",
                        "source": "Sonetto",
                        "status": "",
                        "type": ""
                    },
                    {
                        "url": "http://img.tesco.com/Groceries/pi/467/5000119001467/IDShot_150x300.jpg",
                        "default": "N",
                        "source": "Sonetto",
                        "status": "",
                        "type": ""
                    },
                    {
                        "url": "http://img.tesco.com/Groceries/pi/467/5000119001467/IDShot_45x45.jpg",
                        "default": "N",
                        "source": "Sonetto",
                        "status": "",
                        "type": ""
                    },
                    {
                        "url": "http://img.tesco.com/Groceries/pi/467/5000119001467/IDShot_540x540.jpg",
                        "default": "N",
                        "source": "Sonetto",
                        "status": "",
                        "type": ""
                    }
                ],
                "brandInfo": [
                    {
                        "brand": "TESCO",
                        "source": "RMS"
                    }
                ],
                "statusInfo": [
                    {
                        "status": "Approved",
                        "source": "RMS"
                    }
                ],
                "whatsInBoxInfo": [],
                "prizesAwardsWonInfo": [],
                "commercialHierarchy": {
                    "department": "G13 BAKED BEANS & CAN PASTA",
                    "division": "G AMBIENT DRY GROCERY",
                    "group": "G1 MAIN MEALS",
                    "class": "G13A BAKED BEANS & VARIANTS",
                    "subclass": "G13AABAKED BEANS"
                },
                "GTIN": [],
                "status": "",
                "itemNumber": "050020430",
                "TPNA": "401877209",
                "sellByType": "I",
                "ukEPWIndicator": "N",
                "roiEPWIndicator": "N",
                "tillDescription": "BAKED BEANS",
                "selInfo": [
                    {
                        "lineno": "1",
                        "description": "TESCO BAKED BEAN",
                        "source": "RMS"
                    },
                    {
                        "lineno": "2",
                        "description": "IN TOMATO SAUCE",
                        "source": "RMS"
                    },
                    {
                        "lineno": "3",
                        "description": "220G",
                        "source": "RMS"
                    }
                ],
                "description": "",
                "brand": "",
                "customerFriendlyDescription": "Tesco Baked Beans In Tomato Sauce 220G",
                "components": [],
                "ingredients": [
                    "Haricot beans (49%)",
                    "Water",
                    "Tomato Purèe (20%)",
                    "Sugar",
                    "Modified Maize Starch",
                    "Salt",
                    "Onion Powder",
                    "Colour (Paprika Extract)",
                    "Maltodextrin",
                    "Spice Extracts"
                ],
                "storage": [
                    "Store in a cool, dry place. Once opened transfer contents into a non metallic",
                    "container, cover and refrigerate. Consume within 2 days."
                ],
                "gda": [
                    {
                        "name": "Energy",
                        "value": "190",
                        "percent": "10"
                    },
                    {
                        "name": "Fat",
                        "value": "1.1",
                        "percent": "2"
                    },
                    {
                        "name": "Saturates",
                        "value": "0.2",
                        "percent": "1"
                    },
                    {
                        "name": "Salt",
                        "value": "1.4",
                        "percent": "23"
                    },
                    {
                        "name": "Sugars",
                        "value": "12.1",
                        "percent": "13"
                    }
                ],
                "nutritionalInfo": [
                    {
                        "name": "Typical Values",
                        "perComp": "100g contain",
                        "perServing": "Each can (220g) contains"
                    },
                    {
                        "name": "Energy",
                        "perComp": "365kJ  (87kcal) ",
                        "perServing": "803kJ  (190kcal) "
                    },
                    {
                        "name": "Protein",
                        "perComp": "4.3g",
                        "perServing": "9.5g"
                    },
                    {
                        "name": "Carbohydrate",
                        "perComp": "14.1g",
                        "perServing": "31.0g"
                    },
                    {
                        "name": "Sugars",
                        "perComp": "5.5g",
                        "perServing": "12.1g"
                    },
                    {
                        "name": "Fat",
                        "perComp": "0.5g",
                        "perServing": "1.1g"
                    },
                    {
                        "name": "Saturates",
                        "perComp": "0.1g",
                        "perServing": "0.2g"
                    },
                    {
                        "name": "Fibre",
                        "perComp": "4.1g",
                        "perServing": "9.0g"
                    },
                    {
                        "name": "Salt",
                        "perComp": "0.6g",
                        "perServing": "1.4g"
                    }
                ],
                "allergenInfo": [],
                "defaultImage": "",
                "imageUrl": [],
                "marketingText": "",
                "pkgDimensionInfo": [],
                "productSummaryInfo": [],
                "countryAuthInfo": [
                    "GB",
                    "IE"
                ],
                "suspended": "N",
                "baseDescriptionInfo": [
                    {
                        "lineNo": "1",
                        "description": "TESCO BAKED BEAN",
                        "source": "RMS"
                    },
                    {
                        "lineNo": "2",
                        "description": "IN TOMATO SAUCE ",
                        "source": "RMS"
                    },
                    {
                        "lineNo": "3",
                        "description": "220G            ",
                        "source": "RMS"
                    }
                ],
                "epiSelInfo": [
                    {
                        "lineNo": "1",
                        "description": "",
                        "source": "RMS"
                    },
                    {
                        "lineNo": "2",
                        "description": "",
                        "source": "RMS"
                    },
                    {
                        "lineNo": "3",
                        "description": "",
                        "source": "RMS"
                    },
                    {
                        "lineNo": "4",
                        "description": "",
                        "source": "RMS"
                    },
                    {
                        "lineNo": "5",
                        "description": "",
                        "source": "RMS"
                    }
                ],
                "styleCode": "",
                "unitQty": "KG",
                "epiSelCategory": "",
                "productDatesInfo": [
                    {
                        "country": "GB",
                        "date": "",
                        "dateType": "deactivate",
                        "source": "RMS"
                    },
                    {
                        "country": "IE",
                        "date": "",
                        "dateType": "deactivate",
                        "source": "RMS"
                    },
                    {
                        "country": "GB",
                        "date": "",
                        "dateType": "suspend",
                        "source": "RMS"
                    },
                    {
                        "country": "IE",
                        "date": "",
                        "dateType": "suspend",
                        "source": "RMS"
                    },
                    {
                        "country": "GB",
                        "date": "06/08/1989 00:00:00",
                        "dateType": "launch",
                        "source": "RMS"
                    },
                    {
                        "country": "IE",
                        "date": "22/03/2009 00:00:00",
                        "dateType": "launch",
                        "source": "RMS"
                    }
                ],
                "drainedIndicatorInfo": [
                    {
                        "country": "GB",
                        "indicator": "N",
                        "source": "RMS"
                    },
                    {
                        "country": "IE",
                        "indicator": "N",
                        "source": "RMS"
                    }
                ],
                "quantityInfo": [
                    {
                        "quantity": "220",
                        "quantityUom": "G",
                        "source": "RMS"
                    }
                ],
                "variantReasonCode": "N",
                "commercialHierarchyInfo": {
                    "divisionCode": "G",
                    "divisionNumber": "700",
                    "divisionName": "AMBIENT DRY GROCERY",
                    "departmentCode": "G1",
                    "departmentNumber": "710",
                    "departmentName": "MAIN MEALS",
                    "sectionCode": "G13",
                    "sectionNumber": "713",
                    "sectionName": "BAKED BEANS & CAN PASTA",
                    "classCode": "G13A",
                    "classNumber": "1",
                    "className": "BAKED BEANS & VARIANTS",
                    "subclassCode": "G13AA",
                    "subclassNumber": "1",
                    "subclassName": "BAKED BEANS"
                },
                "href": "http://product.global.tesco.org:8080/v2/products/trn%3Atesco%3Aproduct%3Auuid%3A2cee5245-23a7-4d51-af6d-f63b3e157492"
            }
        ],
        "total": 1,
        "missingSet": []
    }

HTML

    <tr ng-repeat = "oneProduct in products">
                            <td ng-show="EANSwitch"> {{oneProduct.uniqueKey}} </td>
                            <td ng-show="descriptionSwitch"> {{productContentInfo.url}} </td>

Angular JS

    $scope.runSearch = function() {

        $http.get("http://product.global.tesco.org:8080/v2/products?gtin=" + $scope.searchInput).success(function(theData) {

            $scope.products = theData.products;
            $scope.productContentInfo = products.contentInfo
        });

    }
2
  • Unfortunately my upvote doesn't display for either of you as my reputation is too low (first post) but I am so grateful. Commented Jul 30, 2015 at 10:13
  • Upvoted your question, you can upvote answers once you reach 15 reputation. Just 2 more to go. Commented Jul 30, 2015 at 13:10

2 Answers 2

0

I don't understand what you meant by $scope.productContentInfo = products.contentInfo. Maybe you want to use $scope.productContentInfo = $scope.products.contentInfo;. But you can skip it altogether, as you already have this information in $scope.products

  $scope.runSearch = function() {
    $http.get("http://product.global.tesco.org:8080/v2/products?gtin=" + $scope.searchInput).success(function(theData) {
        $scope.products = theData.products;
    });
}

Now, for the HTML, you can have another ng-repeat over contentInfo. So, modified HTML goes something like this:

    <tr ng-repeat = "oneProduct in products">
      <td ng-show="EANSwitch"> {{oneProduct.uniqueKey}} </td>
      <td ng-show="descriptionSwitch" ng-repeat="u in oneProduct.contentInfo"> {{u.url}} </td>
0
0

You could use another ngRepeat

<tr ng-repeat = "oneProduct in products">
    <td ng-show="EANSwitch"> {{oneProduct.uniqueKey}} </td>
    <td ng-show="descriptionSwitch"> {{productContentInfo.url}} </td>
    <td ng-repeat="content in oneProduct.contentInfo">
        {{content.url}}
    </td>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.