簡體   English   中英

在lodash中,如何深層清除?

[英]In lodash how can I deep remove?

我在底部具有這樣的數據結構..我需要從數組中刪除totype.id === 'REG'以及對象屬性budgt所有實例。

我曾嘗試使用下面的代碼來實現的這一部分,並打算做另一次迭代去除budgt從所有剩余totype秒,但似乎並沒有做到這一點的最好辦法。

_.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
          }
        ]
      }
    ]
  }
]

沒有辦法用Lodash描述的方式“深度刪除”。 它沒有像MongoDB這樣的查詢結構。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM