简体   繁体   English

在lodash中,如何深层清除?

[英]In lodash how can I deep remove?

I have a data structure as such at the bottom.. and I need to remove from the array the totype.id === 'REG' and also all instances of the object property budgt . 我在底部具有这样的数据结构..我需要从数组中删除totype.id === 'REG'以及对象属性budgt所有实例。

I have accomplished part of this using the following code, and was going to do another iteration to remove the budgt from all remaining totype s but that didn't seem the best way to do it. 我曾尝试使用下面的代码来实现的这一部分,并打算做另一次迭代去除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
  })
})

sample data 样本数据

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

There is no way to "deep remove" the way you are describing with Lodash. 没有办法用Lodash描述的方式“深度删除”。 It doesn't provide any querying construct like MongoDB. 它没有像MongoDB这样的查询结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM