html52.com
我爱小程序-开发者交流社区

如何删除 一条 记录中的 数组中的 满足条件项 ?

问题描述:如何根据_id查询出该条记录 并删除该条记录judge数组中 满足 id==“111111” 的数据。

{

_id:"all",

judge:[

{"index":0,id:"111111"},

{"index":1,id:"222222"},

{"index":0,id:"111111"},

{"index":1,id:"333333"},

]

}

注意删除的是 该条数据中数组中的数据。

网友回复

stop eating:
        const db = wx.cloud.database();
    const _ = db.command;
    db.collection("code")
    .where({
      _id: '35af80fb5f3b54440000a04857d3c063'
    })
    .update({
      data: {
        judge: _.pull({
          id: _.eq("111111")
        })
      }
    })
?:

写个循环 在循环里

let tempArr = judge;

tempArr.forEach((item,index)=>{

if(item.id=='111111'){

tempArr.splice(index,1)

}

})

judge = tempArr;

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付