私は下部にそのようなデータ構造を持っています。私は配列からtotype.id === 'REG'
とオブジェクトプロパティbudgt
のすべてのインスタンスを削除する必要があります。ロダシュでどのように深く取り除くことができますか?
次のコードを使用してこの部分を達成しましたが、を残りの部分から削除するために別の繰り返しを実行していましたが、これは最善の方法ではありませんでした。
_.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
})
})
サンプルデータ
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
}
]
}
]
}
]
Javasciprtの削除機能を使用してください。すべてのためにlodashを使用しないでください – thangngoc89
大丈夫ですが、反復についてわからないのは効率的ではないようですが、削除すると深い削除を行う方法はありますか? – gorelative