jQuery getjson并在html中导入文本文件

时间:2018-08-31 18:22:52

标签: javascript json

文本文件中大约有40个产品名称,URL,价格,图片链接。

我在这里添加了前三个产品作为示例。

products = [{
            "productId": "PKT-42061",
            "name": "Best of Vinexus 2017 Rotwein (6er-Paket)",
            "price": 49.3,
            "priceText": "€49,30",
            "oldPrice": 58.0,
            "oldPriceText": "€58,00",
            "lastUpdateTime": 1518099000473,
            "inStock": true,
            "insertTime": 1514899645359,
            "publishTime": 1514899645359, 
"brand": "Unsere Selektion",
            "params": {
                "weight": "6 kg",
                "basePrice": "4.5 Liter (10,96 € * / 1 Liter)",
                "likeCount": "2",
                "manLogo": "https://www.vinexus.de/media/image/41/42/bd/unsere-selektion-logo.gif",
                "taxText": "inkl. MwSt. zzgl. Versandkosten",
                "stockText": "Auf Lager. Lieferzeit 1-3 Werktage",
                "isNew": "",
                "land": "",
                "region": "",
                "art": "",
                "stars": "",
                "tastes": "",
                "isAb": "",
                "rebsorte": ""
            }, 
"language": "DE",
            "currency": ""
        }, {
            "productId": "FT-SW-0344-NV",
            "name": "Veuve Clicquot Ponsardin Brut Magnum (1,5L)",
            "price": 107.0,
            "priceText": "€107,00",
            "oldPriceText": "",
            "lastUpdateTime": 1518099000624,
            "inStock": true,
            "insertTime": 1511520818423,
            "publishTime": 1511520818423,
            "brand": "Veuve Clicquot",
            "params": {
                "weight": "1 kg",
                "basePrice": "1.5 Liter (71,33 € * / 1 Liter)",
                "likeCount": "",
                "manLogo": "https://www.vinexus.de/media/image/0b/b4/94/veuve-clicquot.png",
                "taxText": "inkl. MwSt. zzgl. Versandkosten",
                "stockText": "Auf Lager. Lieferzeit 1-3 Werktage",
                "isNew": "",
                "land": "Frankreich",
                "region": "Champagne",
                "art": "Champagner",
                "stars": "",
                "tastes": "brut,",
                "isAb": "",
                "rebsorte": ""
            },
            "language": "DE",
            "currency": ""
        }, 
{
            "productId": "PKT-2821",
            "name": "Weinregion Baden - erstklassige Weingüter (6er-Paket)",
            "price": 66.78,
            "priceText": "€66,78",
            "oldPrice": 74.2,
            "oldPriceText": "€74,20",
            "category": ["Wein > Art > Pakete > Art > Genießer-Pakete", "Wein > Art > Pakete"],
            "categories": ["Wein", "Art", "Pakete", "Genießer-Pakete"],
            "lastUpdateTime": 1518099000702,
            "inStock": true,
            "insertTime": 1517390747188, 
"publishTime": 1517390747188,
            "brand": "Unsere Selektion",
            "params": {
                "weight": "6 kg",
                "basePrice": "4.5 Liter (14,84 € * / 1 Liter)",
                "likeCount": "",
                "manLogo": "https://www.vinexus.de/media/image/41/42/bd/unsere-selektion-logo.gif",
                "taxText": "inkl. MwSt. zzgl. Versandkosten",
                "stockText": "Auf Lager. Lieferzeit 1-3 Werktage",
                "isNew": "true",
                "land": "",
                "region": "",
                "art": "",
                "stars": "",
                "tastes": "",
                "isAb": "", 
"rebsorte": "Cuvée"
            },
            "language": "DE",
            "currency": ""
        }, 

这是问题所在。我想使用foreach循环来打印产品的html标签。

此html文件具有40个商品名称ID标记。如何将所有信息按正确标签的顺序依次放入forEach周期中?如果我能做到这一点而不是一一添加,那就太好了。

还有一件事。我可以将计算机上的本地文本文件上传到html文件,而不是将产品信息粘贴到html文件中吗?因此html文件中没有混乱。

0 个答案:

没有答案