{
"data": [
{
"type": "product",
"id": "138e45b2-5321-8d6c-94d0079ac1f6",
"name": "Hendricks",
"slug": "hendrick",
"sku": "fcusdfckss",
"manage_stock": false,
"description": "hello",
"price": [
{
"amount": 23,
"currency": "gbp",
"includes_tax": true
}
],
"status": "live",
"commodity_type": "physical",
"relationships": {
"categories": {
"data": [
{
"type": "category",
"id": "0d9143-4266-b682-2c8cac60afbb"
}
]
}
},
"meta": {
"display_price": {
"with_tax": {
"amount": 23,
"currency": "GBP",
"formatted": "0.00"
},
"without_tax": {
"amount": 23,
"currency": "GBP",
"formatted": "0.00"
}
},
"stock": {
"level": 0,
"availability": "out-stock"
}
}
},
{
"type": "product",
"id": "726b64bd-9f16-9191-ff1b6a4ef23f",
"name": "Tanquerary",
"slug": "tanq",
"sku": "fghjdsm",
"manage_stock": false,
"description": "A great gin with citrus notes",
"price": [
{
"amount": 88,
"currency": "gbp",
"includes_tax": true
}
],
"status": "live",
"commodity_type": "physical",
"relationships": {
"categories": {
"data": [
{
"type": "category",
"id": "0d914d6d-4266-b682-2c8cac60afbb"
}
]
}
},
"meta": {
"display_price": {
"with_tax": {
"amount": 88,
"currency": "GBP",
"formatted": "0.00"
},
"without_tax": {
"amount": 88,
"currency": "GBP",
"formatted": "0.00"
}
},
"stock": {
"level": 0,
"availability": "out-stock"
}
}
},
{
"type": "product",
"id": "74ab6970-ffdd-4dfd-1816e081cd72",
"name": "Bombay Sapphire",
"slug": "bombay",
"sku": "bomsaph193",
"manage_stock": true,
"description": "A great gin with floral notes",
"price": [
{
"amount": 1999,
"currency": "gbp",
"includes_tax": true
}
],
"status": "live",
"commodity_type": "physical",
"relationships": {
"categories": {
"data": [
{
"type": "category",
"id": "46569361-1352-83e6-13477074f952"
}
]
}
},
"meta": {
"display_price": {
"with_tax": {
"amount": 1999,
"currency": "GBP",
"formatted": "0.00"
},
"without_tax": {
"amount": 1999,
"currency": "GBP",
"formatted": "0.00"
}
},
"stock": {
"level": 5,
"availability": "in-stock"
}
}
}
],
"links": {
"current": "...link...?page[limit]=100&page[offset]=0",
"first": "...link...",
"last": null
},
"meta": {
"results": {
"total": 3,
"all": 3
},
"page": {
"limit": 100,
"offset": 0,
"current": 1,
"total": 1
}
}
}
Ich brauche die Ergebnisse einer zurück JSON-Objekt angezeigt werden Angular 2. Verwendung Ich versuche Lodash zu verwenden, um die nicht benötigten Schlüssel-Wert-Paare auszufiltern.Schleife durch eine JSON in Angular2/Typoskript
Ich habe mit den Werten herausgefiltert:
products.data.forEach(element => {
var prodr = _.pick(products.data, ['0.name', '0.sku', '0.description', '0.price.0.amount']);
console.log(prodr);
});
Dieser Code Schleifen durch die Objekte, sondern gibt Objekte den gleichen Wert, weil ich sie auf „0“ gesetzt haben. Ich denke, ich muss sie auf "ich" setzen und in eine für Funktion hinzufügen, aber ich bin ziemlich neu in Javascript und Typoskript und ich kann nicht die Syntax richtig.
können Sie den json Wert auf den Posten aktualisieren. Auch warum tun Sie ein 'forEach' – Aravind