繁体   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