Ich habe eine Datenstruktur als solche an der Unterseite .. und ich muss aus dem Array die totype.id === 'REG'
und auch alle Instanzen der Objekteigenschaft budgt
entfernen.In lodash wie kann ich tief entfernen?
Ich habe einen Teil davon mit dem folgenden Code ausgeführt, und würde eine weitere Iteration durchführen, um die budgt
von allen verbleibenden totype
s zu entfernen, aber das schien nicht der beste Weg, es zu tun.
_.each(data, function (d, i) { // iterate over each "org"
_.each(d.occs, function (occ) { // iterate over each "occ" in current "org"
return _.remove(occ.totypes, function (totype) { // remove the totype REG from "totypes"
return totype.id === 'REG'
})
// how do i remove the "budgt" from each remaining totype
})
})
Beispieldaten
var data = [
{
org: "org1",
occs: [
{
name: "occ1",
totypes: [
{
id: "REG",
act: 1,
auth: 2,
budgt: 3
},
{
id: "PRV",
act: 1,
auth: 2,
budgt: 3
}
]
},
{
name: "occ2",
totypes: [
{
id: "REG",
act: 1,
auth: 2,
budgt: 3
},
{
id: "PRV",
act: 1,
auth: 2,
budgt: 3
}
]
},
},
{
org: "org2",
occs: [
{
name: "occ1",
totypes: [
{
id: "REG",
act: 1,
auth: 2,
budgt: 3
},
{
id: "PRV",
act: 1,
auth: 2,
budgt: 3
}
]
},
{
name: "occ2",
totypes: [
{
id: "REG",
act: 1,
auth: 2,
budgt: 3
},
{
id: "PRV",
act: 1,
auth: 2,
budgt: 3
}
]
}
]
}
]
Verwenden Sie einfach Javascipt löschen Funktion. Verwenden Sie nicht Lodash für alles – thangngoc89
okay, sicher, aber ich weiß nicht über die Iteration scheint nicht effizient gibt es eine Möglichkeit mit löschen, um eine Tiefenlöschung zu tun? – gorelative